How to use the njwt.Parser function in njwt

To help you get started, we’ve selected a few njwt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stormpath / stormpath-sdk-express / test / authenticateUsernamePasswordForToken.js View on Github external
describe('with a request that contains a valid password-based login',function(){
    var jwtExpr = /[^\.]+\.[^\.]+\.[^;]+/;
    var httpOnlyCookieExpr = /access_token=[^\.]+\.[^\.]+\.[^;]+; Expires=[^;]+; HttpOnly;/;
    var httpsOnlyCookieExpr = /access_token=[^\.]+\.[^\.]+\.[^;]+; Expires=[^;]+; Secure; HttpOnly;/;
    var xsrfTokenCookieExpr = /XSRF-TOKEN=[0-9A-Za-z\-]+; Expires=[^;]+;/;

    var mockLoginPost = {username:'abc',password:'123'};
    var parser = nJwt.Parser().setSigningKey('123');
    var customRequestedScope = 'quiero';
    var customScope = 'my-custom scope';


    describe('and default spConfig options with an https server',function(){

      var app, server;

      function requestedScopeReflection(customScope,requestedScope){
        return [customScope,requestedScope].join(' ');
      }

      before(function(done){
        loginSuccessFixture(function(fixture){
          var spMiddleware = stormpathSdkExpress.createMiddleware({
            appHref: fixture.appHref,
github stormpath / stormpath-sdk-express / test / authenticateForToken.js View on Github external
describe('authenticateForToken',function() {

  var app, server;

  var apiAuthFixture = itFixtureLoader('apiAuth.json');
  var loginAuthFixture = itFixtureLoader('loginAuth.json');

  var jwtExpr = /[^\.]+\.[^\.]+\.[^;]+/;
  var httpsOnlyCookieExpr = /access_token=[^\.]+\.[^\.]+\.[^;]+; Expires=[^;]+; Secure; HttpOnly;/;
  var customScope = 'my-custom scope';
  var customRequestedScope = 'quiero';
  var parser = nJwt.Parser().setSigningKey(apiAuthFixture.apiKeySecret);

  before(function(done){
    var spMiddleware = require('../').createMiddleware({
      appHref: apiAuthFixture.appHref,
      apiKeyId: apiAuthFixture.apiKeyId,
      apiKeySecret: apiAuthFixture.apiKeySecret,
      scopeFactory: function(req,res,authenticationResult,account,requestedScope,done) {
        done(null,requestedScope ? requestedScopeReflection(customScope,customRequestedScope) : '');
      }
    });
    app = express();
    app.use(bodyParser.json());

    spMiddleware.attachDefaults(app);