Skip to content

Commit 3e0196c

Browse files
authored
Merge pull request oauthjs#409 from pjz/Fix-331
Add client/user/scope to model#generateAuthorizationCode
2 parents 03453f5 + 961d174 commit 3e0196c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

docs/model/spec.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ A ``String`` to be used as refresh token.
128128

129129
.. _Model#generateAuthorizationCode:
130130

131-
``generateAuthorizationCode([callback])``
131+
``generateAuthorizationCode(client, user, scope, [callback])``
132132
=========================================
133133

134134
Invoked to generate a new authorization code.
@@ -144,6 +144,12 @@ This model function is **optional**. If not implemented, a default handler is us
144144
+------------+----------+---------------------------------------------------------------------+
145145
| Name | Type | Description |
146146
+============+==========+=====================================================================+
147+
| client | Object | The client the authorization code is generated for. |
148+
+------------+----------+---------------------------------------------------------------------+
149+
| user | Object | The user the authorization code is generated for. |
150+
+------------+----------+---------------------------------------------------------------------+
151+
| scope | String | The scopes associated with the authorization code. Can be ``null``. |
152+
+------------+----------+---------------------------------------------------------------------+
147153
| [callback] | Function | Node-style callback to be used instead of the returned ``Promise``. |
148154
+------------+----------+---------------------------------------------------------------------+
149155

lib/handlers/authorize-handler.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,26 @@ AuthorizeHandler.prototype.handle = function(request, response) {
8383
}
8484

8585
var fns = [
86-
this.generateAuthorizationCode(),
8786
this.getAuthorizationCodeLifetime(),
8887
this.getClient(request),
8988
this.getUser(request, response)
9089
];
9190

9291
return Promise.all(fns)
9392
.bind(this)
94-
.spread(function(authorizationCode, expiresAt, client, user) {
93+
.spread(function(expiresAt, client, user) {
9594
var uri = this.getRedirectUri(request, client);
9695
var scope;
9796
var state;
9897
var ResponseType;
9998

10099
return Promise.bind(this)
101-
.then(function() {
100+
.then(function() {
102101
scope = this.getScope(request);
102+
103+
return this.generateAuthorizationCode(client, user, scope);
104+
})
105+
.then(function(authorizationCode) {
103106
state = this.getState(request);
104107
ResponseType = this.getResponseType(request);
105108

@@ -130,9 +133,9 @@ AuthorizeHandler.prototype.handle = function(request, response) {
130133
* Generate authorization code.
131134
*/
132135

133-
AuthorizeHandler.prototype.generateAuthorizationCode = function() {
136+
AuthorizeHandler.prototype.generateAuthorizationCode = function(client, user, scope) {
134137
if (this.model.generateAuthorizationCode) {
135-
return promisify(this.model.generateAuthorizationCode)();
138+
return promisify(this.model.generateAuthorizationCode)(client, user, scope);
136139
}
137140
return tokenUtil.generateRandomToken();
138141
};

0 commit comments

Comments
 (0)