Gathering detailed insights and metrics for express-jwt-permissions
Gathering detailed insights and metrics for express-jwt-permissions
Gathering detailed insights and metrics for express-jwt-permissions
Gathering detailed insights and metrics for express-jwt-permissions
express-gateway-plugin-jwt-permissions
A plugin for Express Gateway for JWT permissions
express-jwt-permissions-x
Express middleware for JWT permissions forked from express-jwt-permissions
express-jwt-authorization
Express middleware for handling JWT permissions
minapi
Minimum viable API w/ authentication and permissions, CRUD and resource management
🚦 Express middleware for JWT permissions
npm install express-jwt-permissions
Typescript
Module System
Min. Node Version
Node Version
NPM Version
93.3
Supply Chain
99.5
Quality
77.8
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
2,875,284
Last Day
286
Last Week
13,008
Last Month
54,200
Last Year
524,728
MIT License
522 Stars
114 Commits
37 Forks
9 Watchers
7 Branches
11 Contributors
Updated on Mar 08, 2025
Minified
Minified + Gzipped
Latest Version
1.3.7
Package Id
express-jwt-permissions@1.3.7
Unpacked Size
19.45 kB
Size
6.06 kB
File Count
12
NPM Version
6.14.16
Node Version
12.22.12
Cumulative downloads
Total Downloads
Last Day
27.1%
286
Compared to previous day
Last Week
-2.9%
13,008
Compared to previous week
Last Month
-9.6%
54,200
Compared to previous month
Last Year
47.7%
524,728
Compared to previous year
2
3
Middleware that checks JWT tokens for permissions, recommended to be used in conjunction with express-jwt.
npm install express-jwt-permissions --save
This middleware assumes you already have a JWT authentication middleware such as express-jwt.
The middleware will check a decoded JWT token to see if a token has permissions to make a certain request.
Permissions should be described as an array of strings inside the JWT token, or as a space-delimited OAuth 2.0 Access Token Scope string.
1"permissions": [ 2 "status", 3 "user:read", 4 "user:write" 5]
1"scope": "status user:read user:write"
If your JWT structure looks different you should map or reduce the results to produce a simple Array or String of permissions.
To verify a permission for all routes using an array:
1var guard = require('express-jwt-permissions')() 2 3app.use(guard.check('admin'))
If you require different permissions per route, you can set the middleware per route.
1var guard = require('express-jwt-permissions')() 2 3app.get('/status', guard.check('status'), function(req, res) { ... }) 4app.get('/user', guard.check(['user:read']), function(req, res) { ... })
Logical combinations of required permissions can be made using nested arrays.
Single string
1// Required: "admin" 2app.use(guard.check( 3 'admin' 4))
Array of strings
1// Required: "read" AND "write" 2app.use(guard.check( 3 ['read', 'write'] 4))
Array of arrays of strings
1// Required: "read" OR "write" 2app.use(guard.check([ 3 ['read'], 4 ['write'] 5])) 6 7// Required: "admin" OR ("read" AND "write") 8app.use(guard.check([ 9 ['admin'], 10 ['read', 'write'] 11]))
To set where the module can find the user property (default req.user
) you can set the requestProperty
option.
To set where the module can find the permissions property inside the requestProperty
object (default permissions
), set the permissionsProperty
option.
Example:
Consider you've set your permissions as scope
on req.identity
, your JWT structure looks like:
1"scope": "user:read user:write"
You can pass the configuration into the module:
1var guard = require('express-jwt-permissions')({ 2 requestProperty: 'identity', 3 permissionsProperty: 'scope' 4}) 5 6app.use(guard.check('user:read'))
The default behavior is to throw an error when the token is invalid, so you can add your custom logic to manage unauthorized access as follows:
1app.use(guard.check('admin')) 2 3app.use(function (err, req, res, next) { 4 if (err.code === 'permission_denied') { 5 res.status(403).send('Forbidden'); 6 } 7});
Note that your error handling middleware should be defined after the jwt-permissions middleware.
This library has integration with express-unless to allow excluding paths, please refer to their usage.
1const checkForPermissions = guard 2 .check(['admin']) 3 .unless({ path: '/not-secret' }) 4 5app.use(checkForPermissions)
$ npm install
$ npm test
This project is licensed under the MIT license. See the LICENSE file for more info.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 2/13 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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