Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Scope factories on OAuthAuthenticator #575

Merged
merged 4 commits into from
Feb 4, 2017

Conversation

the-overengineer
Copy link

Adds support for setting the scope factory flow properties directly on OAuthAuthenticator instances. The set properties will automatically be passed onto the specific authenticator instance, if it supports scope factories.

This simplifies the scope factory flow in the Express SDK (without requiring additional hacks).

Example (modified from real-world Express SDK use case):

var nJwt = require('njwt');
var req; // Request with client_credentials grant type and 'admin' scope
var authenticator = new stormpath.OAuthAuthenticator(application);

if (config.web.scopeFactory) {
  // Scope factory just returns the requisite scope and appends 'x2' to it
  authenticator.setScopeFactory(config.web.scopeFactory);
  authenticator.setScopeFactorySigningKey(config.client.apiKey.secret);
}

authenticator.authenticate(req, function (err, authResult) {
  if (err) {
     throw err;
  }

  nJwt.verify(authResult.access_token, config.client.apiKey.secret, function (err, token) {
    if (err) {
      throw err;
    }

    console.log(token.body.scope === 'adminx2'); // true
  });
});

@coveralls
Copy link

coveralls commented Nov 25, 2016

Coverage Status

Coverage decreased (-0.1%) to 89.382% when pulling 52cb53a on feature/oauth-authenticator-scope-factory into 43d1ad2 on master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 89.382% when pulling 52cb53a on feature/oauth-authenticator-scope-factory into 43d1ad2 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 89.382% when pulling 52cb53a on feature/oauth-authenticator-scope-factory into 43d1ad2 on master.

@the-overengineer
Copy link
Author

the-overengineer commented Nov 25, 2016

Test failure completely unrelated. Again.

@the-overengineer the-overengineer force-pushed the feature/oauth-authenticator-scope-factory branch from 52cb53a to 2a52d0a Compare January 31, 2017 13:28
@coveralls
Copy link

coveralls commented Jan 31, 2017

Coverage Status

Coverage decreased (-0.1%) to 88.034% when pulling 2a52d0a on feature/oauth-authenticator-scope-factory into d5482d7 on master.

@robertjd robertjd merged commit 848654d into master Feb 4, 2017
@robertjd robertjd deleted the feature/oauth-authenticator-scope-factory branch February 4, 2017 02:29
@robertjd
Copy link
Member

robertjd commented Feb 4, 2017

Thanks @Tweety-FER !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants