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
14 changes: 10 additions & 4 deletions lib/grant-types/abstract-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ function AbstractGrantType(options) {
* Generate access token.
*/

AbstractGrantType.prototype.generateAccessToken = function() {
AbstractGrantType.prototype.generateAccessToken = function(client, user, scope) {
if (this.model.generateAccessToken) {
return promisify(this.model.generateAccessToken)();
return promisify(this.model.generateAccessToken, 3)(client, user, scope)
.then(function(accessToken) {
return accessToken || tokenUtil.generateRandomToken();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's a good idea to fall back to the default generateRandomToken?
I would consider it an error if model#generateAccessToken is implemented but returns a falsy value.

});
}

return tokenUtil.generateRandomToken();
Expand All @@ -47,9 +50,12 @@ AbstractGrantType.prototype.generateAccessToken = function() {
* Generate refresh token.
*/

AbstractGrantType.prototype.generateRefreshToken = function() {
AbstractGrantType.prototype.generateRefreshToken = function(client, user, scope) {
if (this.model.generateRefreshToken) {
return promisify(this.model.generateRefreshToken)();
return promisify(this.model.generateRefreshToken, 3)(client, user, scope)
.then(function(refreshToken) {
return refreshToken || tokenUtil.generateRandomToken();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's a good idea to fall back to the default generateRandomToken?
I would consider it an error if model#generateRefreshToken is implemented but returns a falsy value.

});
}

return tokenUtil.generateRandomToken();
Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/authorization-code-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ AuthorizationCodeGrantType.prototype.revokeAuthorizationCode = function(code) {
AuthorizationCodeGrantType.prototype.saveToken = function(user, client, authorizationCode, scope) {
var fns = [
this.validateScope(user, client, scope),
this.generateAccessToken(),
this.generateRefreshToken()
this.generateAccessToken(client, user, scope),
this.generateRefreshToken(client, user, scope)
];

return Promise.all(fns)
Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/client-credentials-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ ClientCredentialsGrantType.prototype.getUserFromClient = function(client) {
ClientCredentialsGrantType.prototype.saveToken = function(user, client, scope) {
var fns = [
this.validateScope(user, client, scope),
this.generateAccessToken(),
this.getAccessTokenExpiresAt()
this.generateAccessToken(client, user, scope),
this.getAccessTokenExpiresAt(client, user, scope)
];

return Promise.all(fns)
Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/password-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ PasswordGrantType.prototype.getUser = function(request) {
PasswordGrantType.prototype.saveToken = function(user, client, scope) {
var fns = [
this.validateScope(user, client, scope),
this.generateAccessToken(),
this.generateRefreshToken(),
this.generateAccessToken(client, user, scope),
this.generateRefreshToken(client, user, scope),
this.getAccessTokenExpiresAt(),
this.getRefreshTokenExpiresAt()
];
Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/refresh-token-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ RefreshTokenGrantType.prototype.revokeToken = function(token) {

RefreshTokenGrantType.prototype.saveToken = function(user, client, scope) {
var fns = [
this.generateAccessToken(),
this.generateRefreshToken(),
this.generateAccessToken(client, user, scope),
this.generateRefreshToken(client, user, scope),
this.getAccessTokenExpiresAt(),
this.getRefreshTokenExpiresAt()
];
Expand Down
4 changes: 2 additions & 2 deletions test/integration/handlers/token-handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,8 @@ describe('TokenHandler integration', function() {
it('should throw an invalid grant error if a non-oauth error is thrown', function() {
var client = { grants: ['password'] };
var model = {
getClient: function() {},
getUser: function() {},
getClient: function(clientId, password, callback) { callback(null, client); },
getUser: function(uid, pwd, callback) { callback(); },
saveToken: function() {}
};
var handler = new TokenHandler({ accessTokenLifetime: 120, model: model, refreshTokenLifetime: 120 });
Expand Down
4 changes: 2 additions & 2 deletions test/integration/server_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe('Server integration', function() {

it('should return a promise', function() {
var model = {
getAccessToken: function() {
return { user: {} };
getAccessToken: function(token, callback) {
callback(null, { user: {} });
}
};
var server = new Server({ model: model });
Expand Down