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
12 changes: 2 additions & 10 deletions lib/grant-types/authorization-code-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,11 @@ AuthorizationCodeGrantType.prototype.getAuthorizationCode = function(request, cl

AuthorizationCodeGrantType.prototype.revokeAuthorizationCode = function(code) {
return Promise.try(this.model.revokeAuthorizationCode, code)
.then(function(code) {
if (!code) {
.then(function(status) {
if (!status) {
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
}

if (!(code.expiresAt instanceof Date)) {
throw new ServerError('Server error: `expiresAt` must be a Date instance');
}

if (code.expiresAt >= new Date()) {
throw new ServerError('Server error: authorization code should be expired');
}

return code;
});
};
Expand Down
12 changes: 2 additions & 10 deletions lib/grant-types/refresh-token-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,11 @@ RefreshTokenGrantType.prototype.getRefreshToken = function(request, client) {

RefreshTokenGrantType.prototype.revokeToken = function(token) {
return Promise.try(this.model.revokeToken, token)
.then(function(token) {
if (!token) {
.then(function(status) {
if (!status) {
throw new InvalidGrantError('Invalid grant: refresh token is invalid');
}

if (!(token.refreshTokenExpiresAt instanceof Date)) {
throw new ServerError('Server error: `refreshTokenExpiresAt` must be a Date instance');
}

if (token.refreshTokenExpiresAt >= new Date()) {
throw new ServerError('Server error: refresh token should be expired');
}

return token;
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('AuthorizationCodeGrantType integration', function() {
var token = {};
var model = {
getAuthorizationCode: function() { return { authorizationCode: 12345, client: { id: 'foobar' }, expiresAt: new Date(new Date() * 2), user: {} }; },
revokeAuthorizationCode: function() { return { authorizationCode: 12345, client: { id: 'foobar' }, expiresAt: new Date(new Date() / 2), user: {} }; },
revokeAuthorizationCode: function() { return true; },
saveToken: function() { return token; },
validateScope: function() { return 'foo'; }
};
Expand All @@ -133,7 +133,7 @@ describe('AuthorizationCodeGrantType integration', function() {
var client = { id: 'foobar' };
var model = {
getAuthorizationCode: function() { return Promise.resolve({ authorizationCode: 12345, client: { id: 'foobar' }, expiresAt: new Date(new Date() * 2), user: {} }); },
revokeAuthorizationCode: function() { return Promise.resolve({ authorizationCode: 12345, client: { id: 'foobar' }, expiresAt: new Date(new Date() / 2), user: {} }); },
revokeAuthorizationCode: function() { return true; },
saveToken: function() {}
};
var grantType = new AuthorizationCodeGrantType({ accessTokenLifetime: 123, model: model });
Expand All @@ -146,7 +146,7 @@ describe('AuthorizationCodeGrantType integration', function() {
var client = { id: 'foobar' };
var model = {
getAuthorizationCode: function() { return { authorizationCode: 12345, client: { id: 'foobar' }, expiresAt: new Date(new Date() * 2), user: {} }; },
revokeAuthorizationCode: function() { return { authorizationCode: 12345, client: { id: 'foobar' }, expiresAt: new Date(new Date() / 2), user: {} }; },
revokeAuthorizationCode: function() { return true; },
saveToken: function() {}
};
var grantType = new AuthorizationCodeGrantType({ accessTokenLifetime: 123, model: model });
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('AuthorizationCodeGrantType integration', function() {
var authorizationCode = { authorizationCode: 12345, client: {}, expiresAt: new Date(new Date() / 2), redirectUri: 'http://foo.bar', user: {} };
var model = {
getAuthorizationCode: function() {},
revokeAuthorizationCode: function() { return authorizationCode; },
revokeAuthorizationCode: function() { return true; },
saveToken: function() {}
};
var grantType = new AuthorizationCodeGrantType({ accessTokenLifetime: 123, model: model });
Expand All @@ -423,7 +423,7 @@ describe('AuthorizationCodeGrantType integration', function() {
var authorizationCode = { authorizationCode: 12345, client: {}, expiresAt: new Date(new Date() / 2), user: {} };
var model = {
getAuthorizationCode: function() {},
revokeAuthorizationCode: function() { return authorizationCode; },
revokeAuthorizationCode: function() { return true; },
saveToken: function() {}
};
var grantType = new AuthorizationCodeGrantType({ accessTokenLifetime: 123, model: model });
Expand All @@ -439,7 +439,7 @@ describe('AuthorizationCodeGrantType integration', function() {
var authorizationCode = { authorizationCode: 12345, client: {}, expiresAt: new Date(new Date() / 2), user: {} };
var model = {
getAuthorizationCode: function() {},
revokeAuthorizationCode: function() { return Promise.resolve(authorizationCode); },
revokeAuthorizationCode: function() { return Promise.resolve(true); },
saveToken: function() {}
};
var grantType = new AuthorizationCodeGrantType({ accessTokenLifetime: 123, model: model });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('AuthorizationCodeGrantType', function() {
it('should call `model.revokeAuthorizationCode()`', function() {
var model = {
getAuthorizationCode: function() {},
revokeAuthorizationCode: sinon.stub().returns({ authorizationCode: 12345, client: {}, expiresAt: new Date(new Date() / 2), user: {} }),
revokeAuthorizationCode: sinon.stub().returns(true),
saveToken: function() {}
};
var handler = new AuthorizationCodeGrantType({ accessTokenLifetime: 120, model: model });
Expand Down