Skip to content

Commit 0bf1061

Browse files
committed
Merge dev into pkce
2 parents 8de145f + 89173de commit 0bf1061

15 files changed

+905
-22
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The *oauth2-server* module is framework-agnostic but there are several officiall
2222

2323
- Supports `authorization_code`, `client_credentials`, `refresh_token` and `password` grant, as well as *extension grants*, with scopes.
2424
- Can be used with *promises*, *Node-style callbacks*, *ES6 generators* and *async*/*await* (using [Babel](https://babeljs.io)).
25-
- Fully [RFC 6749](https://tools.ietf.org/html/rfc6749.html) and [RFC 6750](https://tools.ietf.org/html/rfc6749.html) compliant.
25+
- Fully [RFC 6749](https://tools.ietf.org/html/rfc6749.html) and [RFC 6750](https://tools.ietf.org/html/rfc6750.html) compliant.
2626
- Implicitly supports any form of storage, e.g. *PostgreSQL*, *MySQL*, *MongoDB*, *Redis*, etc.
2727
- Complete [test suite](https://github.com/oauthjs/node-oauth2-server/tree/master/test).
2828

@@ -63,6 +63,6 @@ npm test
6363
[travis-url]: https://travis-ci.org/oauthjs/node-oauth2-server
6464
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
6565
[license-url]: https://raw.githubusercontent.com/oauthjs/node-oauth2-server/master/LICENSE
66-
[slack-image]: https://img.shields.io/badge/slack-join-E01563.svg
67-
[slack-url]: https://oauthjs.slack.com
66+
[slack-image]: https://slack.oauthjs.org/badge.svg
67+
[slack-url]: https://slack.oauthjs.org
6868

docs/model/spec.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ An ``Object`` representing the access token and associated data.
195195
+------------------------------+--------+--------------------------------------------------+
196196
| token.accessToken | String | The access token passed to ``getAccessToken()``. |
197197
+------------------------------+--------+--------------------------------------------------+
198-
| [token.accessTokenExpiresAt] | Date | The expiry time of the access token. |
198+
| token.accessTokenExpiresAt | Date | The expiry time of the access token. |
199199
+------------------------------+--------+--------------------------------------------------+
200200
| [token.scope] | String | The authorized scope of the access token. |
201201
+------------------------------+--------+--------------------------------------------------+

lib/grant-types/abstract-grant-type.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,15 @@ AbstractGrantType.prototype.generateRefreshToken = function(client, user, scope)
6868
*/
6969

7070
AbstractGrantType.prototype.getAccessTokenExpiresAt = function() {
71-
var expires = new Date();
72-
73-
expires.setSeconds(expires.getSeconds() + this.accessTokenLifetime);
74-
75-
return expires;
71+
return new Date(Date.now() + this.accessTokenLifetime * 1000);
7672
};
7773

7874
/**
7975
* Get refresh token expiration date.
8076
*/
8177

8278
AbstractGrantType.prototype.getRefreshTokenExpiresAt = function() {
83-
var expires = new Date();
84-
85-
expires.setSeconds(expires.getSeconds() + this.refreshTokenLifetime);
86-
87-
return expires;
79+
return new Date(Date.now() + this.refreshTokenLifetime * 1000);
8880
};
8981

9082
/**

lib/handlers/authenticate-handler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ AuthenticateHandler.prototype.handle = function(request, response) {
6363
throw new InvalidArgumentError('Invalid argument: `response` must be an instance of Response');
6464
}
6565

66+
// Extend model object with request
67+
this.model.request = request;
68+
6669
return Promise.bind(this)
6770
.then(function() {
6871
return this.getTokenFromRequest(request);

lib/handlers/authorize-handler.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ AuthorizeHandler.prototype.handle = function(request, response) {
8383
return Promise.reject(new AccessDeniedError('Access denied: user denied access to application'));
8484
}
8585

86+
// Extend model object with request
87+
this.model.request = request;
88+
8689
var fns = [
8790
this.getAuthorizationCodeLifetime(),
8891
this.getClient(request),
@@ -101,13 +104,19 @@ AuthorizeHandler.prototype.handle = function(request, response) {
101104

102105
return Promise.bind(this)
103106
.then(function() {
104-
scope = this.getScope(request);
105107
codeChallenge = this.getCodeChallenge(request, client);
106108

107109
if (codeChallenge) {
108110
codeChallengeMethod = this.getCodeChallengeMethod(request);
109111
}
110112

113+
var requestedScope = this.getScope(request);
114+
115+
return this.validateScope(user, client, requestedScope);
116+
})
117+
.then(function(validScope) {
118+
scope = validScope;
119+
111120
return this.generateAuthorizationCode(client, user, scope);
112121
})
113122
.then(function(authorizationCode) {
@@ -243,6 +252,24 @@ AuthorizeHandler.prototype.getClient = function(request) {
243252
});
244253
};
245254

255+
/**
256+
* Validate requested scope.
257+
*/
258+
AuthorizeHandler.prototype.validateScope = function(user, client, scope) {
259+
if (this.model.validateScope) {
260+
return promisify(this.model.validateScope, 3).call(this.model, user, client, scope)
261+
.then(function (scope) {
262+
if (!scope) {
263+
throw new InvalidScopeError('Invalid scope: Requested scope is invalid');
264+
}
265+
266+
return scope;
267+
});
268+
} else {
269+
return Promise.resolve(scope);
270+
}
271+
};
272+
246273
/**
247274
* Get scope from the request.
248275
*/

lib/handlers/token-handler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ TokenHandler.prototype.handle = function(request, response) {
8686
return Promise.reject(new InvalidRequestError('Invalid request: content must be application/x-www-form-urlencoded'));
8787
}
8888

89+
// Extend model object with request
90+
this.model.request = request;
91+
8992
return Promise.bind(this)
9093
.then(function() {
9194
return this.getClient(request, response);

lib/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ function Request(options) {
3333

3434
// Store the headers in lower case.
3535
for (var field in options.headers) {
36-
if (options.headers.hasOwnProperty(field)) {
36+
if (Object.prototype.hasOwnProperty.call(options.headers, field)) {
3737
this.headers[field.toLowerCase()] = options.headers[field];
3838
}
3939
}
4040

4141
// Store additional properties of the request object passed in
4242
for (var property in options) {
43-
if (options.hasOwnProperty(property) && !this[property]) {
43+
if (Object.prototype.hasOwnProperty.call(options, property) && !this[property]) {
4444
this[property] = options[property];
4545
}
4646
}

lib/response.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ function Response(options) {
1313

1414
// Store the headers in lower case.
1515
for (var field in options.headers) {
16-
if (options.headers.hasOwnProperty(field)) {
16+
if (Object.prototype.hasOwnProperty.call(options.headers, field)) {
1717
this.headers[field.toLowerCase()] = options.headers[field];
1818
}
1919
}
2020

2121
// Store additional properties of the response object passed in
2222
for (var property in options) {
23-
if (options.hasOwnProperty(property) && !this[property]) {
23+
if (Object.prototype.hasOwnProperty.call(options, property) && !this[property]) {
2424
this[property] = options[property];
2525
}
2626
}

0 commit comments

Comments
 (0)