diff --git a/lib/oauth/authenticator.js b/lib/oauth/authenticator.js index 5becd8f2..ad85c11f 100644 --- a/lib/oauth/authenticator.js +++ b/lib/oauth/authenticator.js @@ -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() { @@ -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 {