1.1.0 • Published 6 years ago

@scenid/express-introspection-auth v1.1.0

Weekly downloads
1
License
MIT
Repository
bitbucket
Last release
6 years ago

express-introspection-auth

What is it?

Express middleware that validates OAuth2 tokens against an introspection endpoint to grant access to a resource.

Prerequisite

This middleware expects that the bearer token was extracted beforehand and put into the request object. One way to do this is via middleware express-bearer-token (https://www.npmjs.com/package/express-bearer-token).

Usage

import express from 'express'
import bearerToken from 'express-bearer-token'
import introspectionAuth from 'express-introspection-auth'

const app = express()
const auth = introspectionAuth('http://localhost:3001/token_info')

app.use(bearerToken())

app.all('/justValidateToken', auth(), /* your handler, router, middleware */)

/* Given the introspection endpoint returns a list of allowed scopes for the token, we can validate against them */
app.get('/needsReadScope', auth(['read']), /* your handler, router, middleware */)
app.post('/needsSpecialScopes', auth(['read', 'write']), /* your handler, router, middleware */)

app.listen(8000)

Documentation

1.1.0

6 years ago

1.0.0

7 years ago