Express plugin compatible with OAuth2.0 resource server
https://www.npmjs.com/package/@berlingske-media/bm.node-module.auth_plugin
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 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>');
.
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