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

Commit

Permalink
Add scope factory support to OAuthAuthenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Skukan committed Nov 25, 2016
1 parent 43d1ad2 commit a23e73c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/oauth/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ function OAuthAuthenticator(application) {
this.application = application;
}

OAuthAuthenticator.prototype.setScopeFactory = function setScopeFactory(scopeFactory) {
this.scopeFactory = scopeFactory;
};

OAuthAuthenticator.prototype.setScopeFactorySigningKey = function setScopeFactorySigningKey(key) {
this.signingKey = key;
};

OAuthAuthenticator.prototype.localValidation = false;

OAuthAuthenticator.prototype.withLocalValidation = function withLocalValidation() {
Expand Down Expand Up @@ -77,6 +85,19 @@ OAuthAuthenticator.prototype.authenticate = function authenticate(req, callback)
}
}

if (this.scopeFactory) {
if (!this.signingKey) {
callback(new ApiAuthRequestError({
userMessage: 'Invalid Request',
developerMessage: 'Scope factory cannot be used without a signing key',
statusCode: 400
}));
}

authenticator.setScopeFactory(this.scopeFactory);
authenticator.setScopeFactorySigningKey(this.signingKey);
}

if (authenticator) {
authenticator.authenticate(token, callback);
} else {
Expand Down

0 comments on commit a23e73c

Please sign in to comment.