
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
express-rbac-authz-middleware
Advanced tools
Work in progress. A simple RBAC Authorization middleware for Express. Written in typescript for all your code autocompletion needs.
Work in progress. A simple RBAC Authorization middleware for Express. Written in typescript for all your code autocompletion needs.
npm i --save express-rbac-authz-middleware
import { AuthzMiddleware } from 'express-rbac-authz-middleware';
import { AuthzMiddleware } from 'express-rbac-authz-middleware';
const app = express()
const options = {
tokenDecoder: (req) => ({
id: '123',
roles: ['user']
})
}
app.use(AuthzMiddleware(options))
app.get('/user', (req, resp) => {
req.authz.all('user')
resp.json({ msg: 'Hello User' })
})
app.get('/admin', (req, resp) => {
req.authz.is('admin') // throws AuthzError
resp.json({ msg: 'Hello Admin' })
})
app.get('/guest', (req, resp) => {
resp.json({ msg: 'Hello Guest' })
})
In your express app:
const options = {
tokenDecoder: (req) => ({
id: '123',
roles: ['user']
})
}
app.use(AuthzMiddleware(options))
The API is exposed on the Express Request interface via the authz property.
It has the following functions which you can use to assert authorization rules:
is,all,any
On authorization failure, e.g. a token with roles [user] trying to access a resource protected by req.auth.is("admin"), the function throws an AuthzError. If you want to use a boolean interface instead, you can use the auth.checks methods. These are the same predicates
as above but they return booleans as result instead of throwing an error.
Alternatively you don't have to use strings as your roles. Here's an example using enums:
enum Roles {
Admin = 1,
User = 2,
Support = 3
}
const options: AuthzMiddlewareOptions = {
tokenDecoder: req => ({
id: '123',
roles: [Roles.Admin, Roles.Support]
})
}
Then later in your route you could do the following:
app.get('/admin', (req, resp) => {
req.authz.is(Roles.Admin)
resp.json({ msg: 'Hello Admin' })
})
npm t: Run test suitenpm start: Run npm run build in watch modenpm run test:watch: Run test suite in interactive watch modenpm run test:prod: Run linting and generate coveragenpm run build: Generate bundles and typings, create docsnpm run lint: Lints codenpm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)FAQs
Work in progress. A simple RBAC Authorization middleware for Express. Written in typescript for all your code autocompletion needs.
We found that express-rbac-authz-middleware 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
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.