From a23e73c33f438635545ee33dfa854f90fde032e9 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Fri, 25 Nov 2016 15:12:22 +0100 Subject: [PATCH] Add scope factory support to OAuthAuthenticator --- lib/oauth/authenticator.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 {