Skip to content

Commit 94bbc3b

Browse files
committed
Use preventClearHashAfterLogin consistently
Firefox will show annoying behavior for setting location.hash to an empty string if it already is empty: it refreshes the page or scrolls to the top. The preventClearHashAfterLogin option is passed down to functions to prevent this behavior when it's not needed (e.g. during the results of a silent refresh). However, that option wasn't checked for in a consistent manner. This commit fixes that. Fixes manfredsteyer#493
1 parent a1652dc commit 94bbc3b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

projects/lib/src/oauth-service.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
12641264
}
12651265

12661266
return url;
1267-
1267+
12681268
}
12691269

12701270
initImplicitFlowInternal(
@@ -1503,32 +1503,32 @@ export class OAuthService extends AuthConfig implements OnDestroy {
15031503
(tokenResponse) => {
15041504
this.debug('refresh tokenResponse', tokenResponse);
15051505
this.storeAccessTokenResponse(
1506-
tokenResponse.access_token,
1507-
tokenResponse.refresh_token,
1506+
tokenResponse.access_token,
1507+
tokenResponse.refresh_token,
15081508
tokenResponse.expires_in,
15091509
tokenResponse.scope);
15101510

15111511
if (this.oidc && tokenResponse.id_token) {
1512-
this.processIdToken(tokenResponse.id_token, tokenResponse.access_token).
1512+
this.processIdToken(tokenResponse.id_token, tokenResponse.access_token).
15131513
then(result => {
15141514
this.storeIdToken(result);
1515-
1515+
15161516
this.eventsSubject.next(new OAuthSuccessEvent('token_received'));
15171517
this.eventsSubject.next(new OAuthSuccessEvent('token_refreshed'));
1518-
1518+
15191519
resolve(tokenResponse);
15201520
})
15211521
.catch(reason => {
15221522
this.eventsSubject.next(new OAuthErrorEvent('token_validation_error', reason));
15231523
console.error('Error validating tokens');
15241524
console.error(reason);
1525-
1525+
15261526
reject(reason);
15271527
});
15281528
} else {
15291529
this.eventsSubject.next(new OAuthSuccessEvent('token_received'));
15301530
this.eventsSubject.next(new OAuthSuccessEvent('token_refreshed'));
1531-
1531+
15321532
resolve(tokenResponse);
15331533
}
15341534
},
@@ -1651,7 +1651,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
16511651
.then(result => {
16521652
this.storeIdToken(result);
16531653
this.storeSessionState(sessionState);
1654-
if (this.clearHashAfterLogin) {
1654+
if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) {
16551655
location.hash = '';
16561656
}
16571657
this.eventsSubject.next(new OAuthSuccessEvent('token_received'));
@@ -1688,7 +1688,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
16881688
): boolean {
16891689
const savedNonce = this._storage.getItem('nonce');
16901690
if (savedNonce !== nonceInState) {
1691-
1691+
16921692
const err = 'Validating access_token failed, wrong state/nonce.';
16931693
console.error(err, savedNonce, nonceInState);
16941694
return false;
@@ -1715,7 +1715,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
17151715
if (options.onLoginError) {
17161716
options.onLoginError(parts);
17171717
}
1718-
if (this.clearHashAfterLogin) {
1718+
if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) {
17191719
location.hash = '';
17201720
}
17211721
}

0 commit comments

Comments
 (0)