Skip to content

Commit d1c2bda

Browse files
committed
Passing validated scope into generateAccessToken. oauthjs#620
1 parent 66b92a4 commit d1c2bda

File tree

6 files changed

+12
-20
lines changed

6 files changed

+12
-20
lines changed

lib/grant-types/authorization-code-grant-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ export class AuthorizationCodeGrantType extends AbstractGrantType {
212212
scope: string,
213213
) {
214214
const accessScope = await this.validateScope(user, client, scope);
215-
const accessToken = await this.generateAccessToken(client, user, scope);
216-
const refreshToken = await this.generateRefreshToken(client, user, scope);
215+
const accessToken = await this.generateAccessToken(client, user, accessScope);
216+
const refreshToken = await this.generateRefreshToken(client, user, accessScope);
217217
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
218218
const refreshTokenExpiresAt = this.getRefreshTokenExpiresAt();
219219

lib/grant-types/client-credentials-grant-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class ClientCredentialsGrantType extends AbstractGrantType {
6565

6666
async saveToken(user: User, client: Client, scope: string) {
6767
const accessScope = await this.validateScope(user, client, scope);
68-
const accessToken = await this.generateAccessToken(client, user, scope);
68+
const accessToken = await this.generateAccessToken(client, user, accessScope);
6969
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
7070

7171
const token = {

lib/grant-types/implicit-grant-type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export class ImplicitGrantType extends AbstractGrantType {
4848
*/
4949

5050
async saveToken(user: User, client: Client, scope: string) {
51-
const validatedScope = await this.validateScope(user, client, scope);
52-
const accessToken = await this.generateAccessToken(client, user, scope);
51+
const accessScope = await this.validateScope(user, client, scope);
52+
const accessToken = await this.generateAccessToken(client, user, accessScope);
5353
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
5454

5555
const token = {
5656
accessToken,
5757
accessTokenExpiresAt,
58-
scope: validatedScope,
58+
scope: accessScope,
5959
} as Token;
6060

6161
return this.model.saveToken(token, client, user);

lib/grant-types/password-grant-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export class PasswordGrantType extends AbstractGrantType {
9090

9191
async saveToken(user: User, client: Client, scope: string) {
9292
const accessScope = await this.validateScope(user, client, scope);
93-
const accessToken = await this.generateAccessToken(client, user, scope);
94-
const refreshToken = await this.generateRefreshToken(client, user, scope);
93+
const accessToken = await this.generateAccessToken(client, user, accessScope);
94+
const refreshToken = await this.generateRefreshToken(client, user, accessScope);
9595
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
9696
const refreshTokenExpiresAt = this.getRefreshTokenExpiresAt();
9797

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ export class RefreshTokenGrantType extends AbstractGrantType {
135135
*/
136136

137137
async saveToken(user: User, client: Client, scope: string) {
138-
const accessToken = await this.generateAccessToken(client, user, scope);
139-
const refreshToken = await this.generateRefreshToken(client, user, scope);
138+
const accessScope = await this.validateScope(user, client, scope);
139+
const accessToken = await this.generateAccessToken(client, user, accessScope);
140+
const refreshToken = await this.generateRefreshToken(client, user, accessScope);
140141
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
141142
const refreshTokenExpiresAt = this.getRefreshTokenExpiresAt();
142143

143144
const token: any = {
144145
accessToken,
145146
accessTokenExpiresAt,
146-
scope,
147+
scope: accessScope,
147148
};
148149

149150
if (this.alwaysIssueNewRefreshToken !== false) {

test/unit/grant-types/refresh-token-grant-type.spec.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ describe('RefreshTokenGrantType', () => {
211211
model.saveToken.firstCall.args[1].should.equal(client);
212212
model.saveToken.firstCall.args[2].should.equal(user);
213213
model.saveToken.firstCall.thisValue.should.equal(model);
214-
})
215-
.catch(() => {
216-
should.fail('should.fail', '');
217214
});
218215
});
219216

@@ -249,9 +246,6 @@ describe('RefreshTokenGrantType', () => {
249246
model.saveToken.firstCall.args[1].should.equal(client);
250247
model.saveToken.firstCall.args[2].should.equal(user);
251248
model.saveToken.firstCall.thisValue.should.equal(model);
252-
})
253-
.catch(() => {
254-
should.fail('should.fail', '');
255249
});
256250
});
257251

@@ -289,9 +283,6 @@ describe('RefreshTokenGrantType', () => {
289283
model.saveToken.firstCall.args[1].should.equal(client);
290284
model.saveToken.firstCall.args[2].should.equal(user);
291285
model.saveToken.firstCall.thisValue.should.equal(model);
292-
})
293-
.catch(() => {
294-
should.fail('should.fail', '');
295286
});
296287
});
297288
});

0 commit comments

Comments
 (0)