Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/model/spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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``. |
+------------+----------+---------------------------------------------------------------------+

Expand Down
13 changes: 8 additions & 5 deletions lib/handlers/authorize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,26 @@ AuthorizeHandler.prototype.handle = function(request, response) {
}

var fns = [
this.generateAuthorizationCode(),
this.getAuthorizationCodeLifetime(),
this.getClient(request),
this.getUser(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);

Expand Down Expand Up @@ -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();
};
Expand Down