Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
express-basic-token
Advanced tools
Express/conect middleware for basic token authentication.
This is a very basic authentication middleware which simply looks for a present token in query, body or headers. This could be used for basic APIs which do not require a complex authentication or authorization process. But at the same time it adds some level of security to prevent from completely open public access to your API (e.g. useful for internal company APIs).
$ npm install express-basic-token --save
token
(String
) - Token secret key.tokenName
(String
) - Token name which will be searched for in query, params or headers. Default: x-access-token
notAuthorizedJSON
(Object
) - object returned to the client when token does not match. Default: { message: 'Not Authorized' }
invalidTokenJSON
(Object
) - object returned to the client when token is not present or listed in multiple places. Default: { message: 'Invalid Token' }
Basic usage
ES5
var basicAuthToken = require('express-basic-token');
app.use(basicAuthToken({ token: 'very-secret' });
ES6
import basicAuthToken from 'express-basic-token';
app.use(basicAuthToken({ token: 'very-secret' });
To apply middleware for specific routes
app.use('/protected/*', basicAuthToken({ token: 'very-secret' });
To make exception for protected routes
app.use('/protected/*', basicAuthToken({ token: 'very-secret' }).unless({ path: ['/protected/not/this/one'] }));
or another example
app.use(basicAuthToken({ token: 'very-secret' }).unless({ path: ['/not-protected/*'] }));
Unless allows you to specify array or regex or string or for any other extra options, please see express-unless.
You can specify your custom error objects for invalid token authorization
app.use(basicAuthToken({
token: 'very-secret',
invalidTokenJSON: { message: 'Server Error' },
notAuthorizedJSON: { message: 'Not Allowed!' }
});
To specify custom token header
app.use(basicAuthToken({
token: 'very-secret',
tokenName: 'MY-TOKEN'
});
MIT license; see LICENSE.
FAQs
Express/conect middleware for basic token authentication.
We found that express-basic-token demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.