Installations
npm install basic-auth
Developer
jshttp
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>= 0.8
Typescript Support
No
Node Version
8.12.0
NPM Version
6.4.1
Statistics
702 Stars
129 Commits
86 Forks
22 Watching
1 Branches
33 Contributors
Updated on 25 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
1,639,098,511
Last day
-0.5%
1,721,321
Compared to previous day
Last week
3.2%
9,069,048
Compared to previous week
Last month
9.1%
37,211,730
Compared to previous month
Last year
21.9%
380,733,340
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
basic-auth
Generic basic auth Authorization header field parser for whatever.
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install basic-auth
API
1var auth = require('basic-auth')
auth(req)
Get the basic auth credentials from the given request. The Authorization
header is parsed and if the header is invalid, undefined
is returned,
otherwise an object with name
and pass
properties.
auth.parse(string)
Parse a basic auth authorization header string. This will return an object
with name
and pass
properties, or undefined
if the string is invalid.
Example
Pass a Node.js request object to the module export. If parsing fails
undefined
is returned, otherwise an object with .name
and .pass
.
1var auth = require('basic-auth') 2var user = auth(req) 3// => { name: 'something', pass: 'whatever' }
A header string from any other location can also be parsed with
auth.parse
, for example a Proxy-Authorization
header:
1var auth = require('basic-auth') 2var user = auth.parse(req.getHeader('Proxy-Authorization'))
With vanilla node.js http server
1var http = require('http') 2var auth = require('basic-auth') 3var compare = require('tsscmp') 4 5// Create server 6var server = http.createServer(function (req, res) { 7 var credentials = auth(req) 8 9 // Check credentials 10 // The "check" function will typically be against your user store 11 if (!credentials || !check(credentials.name, credentials.pass)) { 12 res.statusCode = 401 13 res.setHeader('WWW-Authenticate', 'Basic realm="example"') 14 res.end('Access denied') 15 } else { 16 res.end('Access granted') 17 } 18}) 19 20// Basic function to validate credentials for example 21function check (name, pass) { 22 var valid = true 23 24 // Simple method to prevent short-circuit and use timing-safe compare 25 valid = compare(name, 'john') && valid 26 valid = compare(pass, 'secret') && valid 27 28 return valid 29} 30 31// Listen 32server.listen(3000)
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/jshttp/.github/SECURITY.md:1
- Warn: no linked content found
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/jshttp/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/jshttp/.github/SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:133: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/basic-auth/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:206: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/basic-auth/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:218: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/basic-auth/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:166
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:182
- Info: 3 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 3 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
Reason
Found 5/26 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: topLevel permissions set to 'read-all': .github/workflows/scorecard.yml:18
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Score
3.9
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More