cti-jwt-dealer-strategy
v2.0.0
Published
JWT token signer and a Passport strategy for authenticating dealers based on a bearer JWT header
Downloads
3
Maintainers
Readme
cti-passport-jwt-bearer-strategy
JWT token signer and a Passport strategy for authenticating requests based on CTI bearer tokens and assigning relevant scopes.
Usage
const express = require( 'express' );
const passport = require( 'passport' );
const jwtDealerStrategy = require( 'cti-jwt-dealer-strategy' );
const key = 'key';
const issuer = 'issuer';
const audience = 'audience';
const strategy = jwtDealerStrategy.passportStrategy(
key,
{ issuer: issuer, audience: audience }
);
passport.use( strategy );
const bearerAuthenticator =
passport.authenticate( strategy.name, { session: false } );
const app = express();
express.get( '/', bearerAuthenticator, ( req, res ) => {
res.send( 'You\'ve authenticated!' );
} );
const jwtDealerStrategy = require( 'cti-jwt-dealer-strategy' );
const payload = {
uid: 'foo',
dealerId: 'bar'
};
const key = 'key';
const options = {
issuer: 'issuer',
audience: 'audience',
expiresIn: 60
};
const token = jwtDealerStrategy.signToken(
payload,
key,
options
);
console.log( token );