Skip to content

Commit f5bd96c

Browse files
committed
fix: Disable nonce validation for id token for e2e tests
1 parent 8d152c2 commit f5bd96c

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

projects/lib/src/oauth-service.ts

+21-13
Original file line numberDiff line numberDiff line change
@@ -1649,15 +1649,17 @@ export class OAuthService extends AuthConfig implements OnDestroy {
16491649
return Promise.reject(err);
16501650
}
16511651

1652-
if (!nonceInState) {
1653-
return Promise.resolve();
1654-
}
1652+
if (!options.disableNonceCheck) {
1653+
if (!nonceInState) {
1654+
return Promise.resolve();
1655+
}
16551656

1656-
const success = this.validateNonce(nonceInState);
1657-
if (!success) {
1658-
const event = new OAuthErrorEvent('invalid_nonce_in_state', null);
1659-
this.eventsSubject.next(event);
1660-
return Promise.reject(event);
1657+
const success = this.validateNonce(nonceInState);
1658+
if (!success) {
1659+
const event = new OAuthErrorEvent('invalid_nonce_in_state', null);
1660+
this.eventsSubject.next(event);
1661+
return Promise.reject(event);
1662+
}
16611663
}
16621664

16631665
this.storeSessionState(sessionState);
@@ -1717,10 +1719,15 @@ export class OAuthService extends AuthConfig implements OnDestroy {
17171719
}
17181720
}
17191721

1720-
return this.fetchAndProcessToken(params);
1722+
return this.fetchAndProcessToken(params, options);
17211723
}
17221724

1723-
private fetchAndProcessToken(params: HttpParams): Promise<TokenResponse> {
1725+
private fetchAndProcessToken(
1726+
params: HttpParams,
1727+
options: LoginOptions
1728+
): Promise<TokenResponse> {
1729+
options = options || {};
1730+
17241731
this.assertUrlNotNullAndCorrectProtocol(
17251732
this.tokenEndpoint,
17261733
'tokenEndpoint'
@@ -1767,7 +1774,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
17671774
if (this.oidc && tokenResponse.id_token) {
17681775
this.processIdToken(
17691776
tokenResponse.id_token,
1770-
tokenResponse.access_token
1777+
tokenResponse.access_token,
1778+
options.disableNonceCheck
17711779
)
17721780
.then(result => {
17731781
this.storeIdToken(result);
@@ -1871,7 +1879,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
18711879
);
18721880
}
18731881

1874-
if (this.requestAccessToken && !options.disableOAuth2StateCheck) {
1882+
if (this.requestAccessToken && !options.disableNonceCheck) {
18751883
const success = this.validateNonce(nonceInState);
18761884

18771885
if (!success) {
@@ -1900,7 +1908,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
19001908
return Promise.resolve(true);
19011909
}
19021910

1903-
return this.processIdToken(idToken, accessToken)
1911+
return this.processIdToken(idToken, accessToken, options.disableNonceCheck)
19041912
.then(result => {
19051913
if (options.validationHandler) {
19061914
return options

projects/lib/src/types.ts

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ export class LoginOptions {
4949
*/
5050
disableOAuth2StateCheck?: boolean;
5151

52+
/**
53+
* Set this to true to disable the nonce
54+
* check which is used to avoid
55+
* replay attacks.
56+
* This flag should never be true in
57+
* production environments.
58+
*/
59+
disableNonceCheck? = false;
60+
5261
/**
5362
* Normally, you want to clear your hash fragment after
5463
* the lib read the token(s) so that they are not displayed

0 commit comments

Comments
 (0)