JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 41947
  • Score
    100M100P100Q159062F

Bearer token middleware for express.

Package Exports

  • express-bearer-token

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-bearer-token) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

express-bearer-token Build Status

Bearer token middleware for express.

NPM

What?

Per RFC6750 this module will attempt to extract a bearer token from a request from these locations:

  • The key access_token in the request body.
  • The key access_token in the request params.
  • The value from the header Authorization: Bearer <token>.

If a token is found, it will be stored on req.token. If one has been provided in more than one location, this will abort the request immediately by sending code 400 (per RFC6750).

const express = require('express');
const bearerToken = require('express-bearer-token');
const app = express();

app.use(bearerToken());
app.use(function (req, res) {
  res.send('Token '+req.token);
});
app.listen(8000);

For APIs which are not compliant with RFC6750, the key for the token in each location is customizable (default configuration shown):

app.use(bearerToken({
  bodyKey: 'access_token',
  queryKey: 'access_token',
  headerKey: 'Bearer'
}));