Gathering detailed insights and metrics for basic-auth
Gathering detailed insights and metrics for basic-auth
Gathering detailed insights and metrics for basic-auth
Gathering detailed insights and metrics for basic-auth
Generic basic auth Authorization header field parser
npm install basic-auth
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.3
Supply Chain
99.4
Quality
81.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,866,494,407
Last Day
470,945
Last Week
8,864,526
Last Month
38,413,196
Last Year
430,172,034
MIT License
702 Stars
139 Commits
89 Forks
21 Watchers
1 Branches
32 Contributors
Updated on Jun 24, 2025
Minified
Minified + Gzipped
Latest Version
2.0.1
Package Id
basic-auth@2.0.1
Size
3.66 kB
NPM Version
6.4.1
Node Version
8.12.0
Published on
Sep 20, 2018
Cumulative downloads
Total Downloads
Last Day
3.4%
470,945
Compared to previous day
Last Week
-7.3%
8,864,526
Compared to previous week
Last Month
2.2%
38,413,196
Compared to previous month
Last Year
28.1%
430,172,034
Compared to previous year
Generic basic auth Authorization header field parser for whatever.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install basic-auth
1var auth = require('basic-auth')
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.
Parse a basic auth authorization header string. This will return an object
with name
and pass
properties, or undefined
if the string is invalid.
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'))
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-circut 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)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
update tool detected
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
project has 13 contributing companies or organizations
Details
Reason
security policy file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7
Reason
11 out of 16 merged PRs checked by a CI test -- score normalized to 6
Reason
Found 7/21 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-23T21:29:53Z
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