Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
express-oauth2-jwt-bearer
Advanced tools
Authentication middleware for Express.js that validates JWT bearer access tokens.
📚 Documentation - 🚀 Getting Started - 💻 API Reference - 💬 Feedback
This package supports the following tooling versions:
^12.19.0 || ^14.15.0 || ^16.13.0 || ^18.12.0 || ^20.2.0
Using npm in your project directory run the following command:
npm install express-oauth2-jwt-bearer
The library requires issuerBaseURL and audience.
ISSUER_BASE_URL=https://YOUR_ISSUER_DOMAIN
AUDIENCE=https://my-api.com
const { auth } = require('express-oauth2-jwt-bearer');
app.use(auth());
const { auth } = require('express-oauth2-jwt-bearer');
app.use(
auth({
issuerBaseURL: 'https://YOUR_ISSUER_DOMAIN',
audience: 'https://my-api.com',
})
);
HS256
)const { auth } = require('express-oauth2-jwt-bearer');
app.use(
auth({
issuer: 'https://YOUR_ISSUER_DOMAIN',
audience: 'https://my-api.com',
secret: 'YOUR SECRET',
tokenSigningAlg: 'HS256',
})
);
With this configuration, your api will require a valid Access Token JWT bearer token for all routes.
Successful requests will have the following properties added to them:
app.get('/api/messages', (req, res, next) => {
const auth = req.auth;
auth.header; // The decoded JWT header.
auth.payload; // The decoded JWT payload.
auth.token; // The raw JWT token.
});
Along with the other security best practices in the Express.js documentation, we recommend you use helmet in addition to this middleware which can help protect your app from some well-known web vulnerabilities by setting default security HTTP headers.
This SDK raises errors with err.status
and err.headers
according to rfc6750. The Express.js default error handler will set the error response with:
res.statusCode
set from err.status
res.statusMessage
set according to the status code.err.stack
.err.headers
object.The error_description
in the WWW-Authenticate
header will contain useful information about the error, which you may not want to disclose in Production.
See the Express.js docs on error handling for more information on writing custom error handlers.
req.auth
upon successful authorization.insufficient_scope
error if the value of the scope claim does not include all the given scopes.invalid_token
error if the value of the claim does not match.invalid_token
error if the value of the claim does not include all the given values.true
if the token is valid. Raises a 401 invalid_token
error if the function returns false
.We appreciate feedback and contribution to this repo! Before you get started, please see the following:
To provide feedback or report a bug, please raise an issue on our issue tracker.
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the MIT license. See the LICENSE file for more info.
FAQs
Authentication middleware for Express.js that validates JWT bearer access tokens.
The npm package express-oauth2-jwt-bearer receives a total of 76,120 weekly downloads. As such, express-oauth2-jwt-bearer popularity was classified as popular.
We found that express-oauth2-jwt-bearer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 44 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.