diff --git a/docs/model/spec.rst b/docs/model/spec.rst index 5286663f3..341e50ee9 100644 --- a/docs/model/spec.rst +++ b/docs/model/spec.rst @@ -128,7 +128,7 @@ A ``String`` to be used as refresh token. .. _Model#generateAuthorizationCode: -``generateAuthorizationCode([callback])`` +``generateAuthorizationCode(client, user, scope, [callback])`` ========================================= Invoked to generate a new authorization code. @@ -144,6 +144,12 @@ This model function is **optional**. If not implemented, a default handler is us +------------+----------+---------------------------------------------------------------------+ | Name | Type | Description | +============+==========+=====================================================================+ +| client | Object | The client the authorization code is generated for. | ++------------+----------+---------------------------------------------------------------------+ +| user | Object | The user the authorization code is generated for. | ++------------+----------+---------------------------------------------------------------------+ +| scope | String | The scopes associated with the authorization code. Can be ``null``. | ++------------+----------+---------------------------------------------------------------------+ | [callback] | Function | Node-style callback to be used instead of the returned ``Promise``. | +------------+----------+---------------------------------------------------------------------+ diff --git a/lib/handlers/authorize-handler.js b/lib/handlers/authorize-handler.js index 40b7b6cf1..bc0d132e4 100644 --- a/lib/handlers/authorize-handler.js +++ b/lib/handlers/authorize-handler.js @@ -83,7 +83,6 @@ AuthorizeHandler.prototype.handle = function(request, response) { } var fns = [ - this.generateAuthorizationCode(), this.getAuthorizationCodeLifetime(), this.getClient(request), this.getUser(request, response) @@ -91,15 +90,19 @@ AuthorizeHandler.prototype.handle = function(request, response) { return Promise.all(fns) .bind(this) - .spread(function(authorizationCode, expiresAt, client, user) { + .spread(function(expiresAt, client, user) { var uri = this.getRedirectUri(request, client); var scope; var state; var ResponseType; return Promise.bind(this) - .then(function() { + .then(function() { scope = this.getScope(request); + + return this.generateAuthorizationCode(client, user, scope); + }) + .then(function(authorizationCode) { state = this.getState(request); ResponseType = this.getResponseType(request); @@ -130,9 +133,9 @@ AuthorizeHandler.prototype.handle = function(request, response) { * Generate authorization code. */ -AuthorizeHandler.prototype.generateAuthorizationCode = function() { +AuthorizeHandler.prototype.generateAuthorizationCode = function(client, user, scope) { if (this.model.generateAuthorizationCode) { - return promisify(this.model.generateAuthorizationCode)(); + return promisify(this.model.generateAuthorizationCode)(client, user, scope); } return tokenUtil.generateRandomToken(); };