Skip to content

Commit 01e723d

Browse files
authored
Merge branch 'feature/rfc7009' into rfc7009
2 parents 4d8f9c4 + 2d37b2d commit 01e723d

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

lib/grant-types/refresh-token-grant-type.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ class RefreshTokenGrantType extends AbstractGrantType {
5454

5555
let token;
5656
token = await this.getRefreshToken(request, client);
57-
token = await this.revokeToken(token);
5857

58+
// Validate scope before revoking token to prevent destroying tokens on scope validation errors
5959
const scope = this.getScope(request, token);
6060

61+
token = await this.revokeToken(token);
62+
6163
return this.saveToken(token.user, client, scope);
6264
}
6365

package-lock.json

Lines changed: 9 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@node-oauth/oauth2-server",
33
"description": "Complete, framework-agnostic, compliant and well tested module for implementing an OAuth2 Server in node.js",
4-
"version": "5.2.0",
4+
"version": "5.2.2-rc.0",
55
"keywords": [
66
"oauth",
77
"oauth2"

test/integration/grant-types/refresh-token-grant-type_test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
const InvalidArgumentError = require('../../../lib/errors/invalid-argument-error');
88
const InvalidGrantError = require('../../../lib/errors/invalid-grant-error');
99
const InvalidRequestError = require('../../../lib/errors/invalid-request-error');
10+
const InvalidScopeError = require('../../../lib/errors/invalid-scope-error');
1011
const RefreshTokenGrantType = require('../../../lib/grant-types/refresh-token-grant-type');
1112
const Model = require('../../../lib/model');
1213
const Request = require('../../../lib/request');
@@ -183,6 +184,34 @@ describe('RefreshTokenGrantType integration', function() {
183184

184185
grantType.handle(request, client).should.be.an.instanceOf(Promise);
185186
});
187+
188+
it('should throw an error if extra `scope` is requested', async function() {
189+
const client = { id: 123 };
190+
const token = {
191+
accessToken: 'foo',
192+
client: { id: 123 },
193+
user: { name: 'foo' },
194+
refreshTokenExpiresAt: new Date(new Date() * 2)
195+
};
196+
const model = {
197+
getRefreshToken: async function() {
198+
return token;
199+
},
200+
revokeToken: () => should.fail(),
201+
saveToken: () => should.fail()
202+
};
203+
const grantType = new RefreshTokenGrantType({ accessTokenLifetime: 123, model });
204+
const request = new Request({ body: { refresh_token: 'foobar', scope: 'read' }, headers: {}, method: {}, query: {} });
205+
206+
try {
207+
await grantType.handle(request, client);
208+
209+
should.fail();
210+
} catch (e) {
211+
e.should.be.an.instanceOf(InvalidScopeError);
212+
e.message.should.equal('Invalid scope: Unable to add extra scopes');
213+
}
214+
});
186215
});
187216

188217
describe('getRefreshToken()', function() {

0 commit comments

Comments
 (0)