@berlingske-media/bm.node-module.auth_plugin
TypeScript icon, indicating that this package has built-in type declarations

4.0.2 • Public • Published

Express plugin compatible with OAuth2.0 resource server

NPM:

https://www.npmjs.com/package/@berlingske-media/bm.node-module.auth_plugin

Generic usage

On application start

import init function from lib/shared and run await init()

Do not define OAUTH_SERVICE_HOST when you want to switch plugin off on particular instance

To sign your request

to another verified backend server sign your request with token import token getter with

import { getAccessToken } from 'lib/shared'

and use token as follows:

await request.get('/anything')
        .set('Authorization', 'Bearer <TOKEN>');

.

Express integration

in order to integrate plugin with express app use this code snippet

import { OAuthMiddleware } from '../lib/oauthExpressMiddleware';

//initialize before
(await OAuthMiddleware.initialize()).setCustomLogger(logger);

// and then use as a middleware
app.use(OAuthMiddleware.Backend);


// or validate single route with:
app.get('/', OAuthMiddleware.Backend, (req, res) => {
  res.status(StatusCodes.OK).send(ReasonPhrases.OK);
});

Available by default scopes are:

  • OAuthMiddleware.Backend // passes check for ['backend'] scope
  • OAuthMiddleware.Admin // passes check for ['admin'] scope
  • OAuthMiddleware.Custom['anything', 'can', 'go', 'here']

Backend and Admin by default enable time measure of service response time when it exceeds 1s

Readme

Keywords

Package Sidebar

Install

npm i @berlingske-media/bm.node-module.auth_plugin

Weekly Downloads

83

Version

4.0.2

License

Apache-2.0

Unpacked Size

48.9 kB

Total Files

42

Last publish

Collaborators

  • bmxape
  • berlingskemedia
  • bm-berlingske
  • bm-bt
  • bm-business
  • kbukowski
  • xpiku