Skip to content

Commit

Permalink
Passing validated scope into generateAccessToken. oauthjs#620
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdogo committed Oct 12, 2020
1 parent 66b92a4 commit d1c2bda
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/grant-types/authorization-code-grant-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export class AuthorizationCodeGrantType extends AbstractGrantType {
scope: string,
) {
const accessScope = await this.validateScope(user, client, scope);
const accessToken = await this.generateAccessToken(client, user, scope);
const refreshToken = await this.generateRefreshToken(client, user, scope);
const accessToken = await this.generateAccessToken(client, user, accessScope);
const refreshToken = await this.generateRefreshToken(client, user, accessScope);
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
const refreshTokenExpiresAt = this.getRefreshTokenExpiresAt();

Expand Down
2 changes: 1 addition & 1 deletion lib/grant-types/client-credentials-grant-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ClientCredentialsGrantType extends AbstractGrantType {

async saveToken(user: User, client: Client, scope: string) {
const accessScope = await this.validateScope(user, client, scope);
const accessToken = await this.generateAccessToken(client, user, scope);
const accessToken = await this.generateAccessToken(client, user, accessScope);
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();

const token = {
Expand Down
6 changes: 3 additions & 3 deletions lib/grant-types/implicit-grant-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class ImplicitGrantType extends AbstractGrantType {
*/

async saveToken(user: User, client: Client, scope: string) {
const validatedScope = await this.validateScope(user, client, scope);
const accessToken = await this.generateAccessToken(client, user, scope);
const accessScope = await this.validateScope(user, client, scope);
const accessToken = await this.generateAccessToken(client, user, accessScope);
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();

const token = {
accessToken,
accessTokenExpiresAt,
scope: validatedScope,
scope: accessScope,
} as Token;

return this.model.saveToken(token, client, user);
Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/password-grant-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export class PasswordGrantType extends AbstractGrantType {

async saveToken(user: User, client: Client, scope: string) {
const accessScope = await this.validateScope(user, client, scope);
const accessToken = await this.generateAccessToken(client, user, scope);
const refreshToken = await this.generateRefreshToken(client, user, scope);
const accessToken = await this.generateAccessToken(client, user, accessScope);
const refreshToken = await this.generateRefreshToken(client, user, accessScope);
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
const refreshTokenExpiresAt = this.getRefreshTokenExpiresAt();

Expand Down
7 changes: 4 additions & 3 deletions lib/grant-types/refresh-token-grant-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ export class RefreshTokenGrantType extends AbstractGrantType {
*/

async saveToken(user: User, client: Client, scope: string) {
const accessToken = await this.generateAccessToken(client, user, scope);
const refreshToken = await this.generateRefreshToken(client, user, scope);
const accessScope = await this.validateScope(user, client, scope);
const accessToken = await this.generateAccessToken(client, user, accessScope);
const refreshToken = await this.generateRefreshToken(client, user, accessScope);
const accessTokenExpiresAt = this.getAccessTokenExpiresAt();
const refreshTokenExpiresAt = this.getRefreshTokenExpiresAt();

const token: any = {
accessToken,
accessTokenExpiresAt,
scope,
scope: accessScope,
};

if (this.alwaysIssueNewRefreshToken !== false) {
Expand Down
9 changes: 0 additions & 9 deletions test/unit/grant-types/refresh-token-grant-type.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ describe('RefreshTokenGrantType', () => {
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(() => {
should.fail('should.fail', '');
});
});

Expand Down Expand Up @@ -249,9 +246,6 @@ describe('RefreshTokenGrantType', () => {
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(() => {
should.fail('should.fail', '');
});
});

Expand Down Expand Up @@ -289,9 +283,6 @@ describe('RefreshTokenGrantType', () => {
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(() => {
should.fail('should.fail', '');
});
});
});
Expand Down

0 comments on commit d1c2bda

Please sign in to comment.