@@ -1239,6 +1239,18 @@ export class OAuthService extends AuthConfig {
1239
1239
}
1240
1240
}
1241
1241
1242
+ private clearHash ( ) {
1243
+ // By @AndyE at https://stackoverflow.com/a/5298684/419956
1244
+ if ( 'pushState' in history ) {
1245
+ // Clears the hash *including* the hash sigh, cross-browser.
1246
+ history . pushState ( '' , document . title , location . pathname + location . search ) ;
1247
+ } else {
1248
+ // Fallback for older browsers, might leave the '#' character in the address
1249
+ // bar in some cases.
1250
+ location . hash = '' ;
1251
+ }
1252
+ }
1253
+
1242
1254
/**
1243
1255
* Checks whether there are tokens in the hash fragment
1244
1256
* as a result of the implicit flow. These tokens are
@@ -1333,7 +1345,7 @@ export class OAuthService extends AuthConfig {
1333
1345
if ( ! this . oidc ) {
1334
1346
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
1335
1347
if ( this . clearHashAfterLogin && ! options . preventClearHashAfterLogin ) {
1336
- location . hash = '' ;
1348
+ this . clearHash ( ) ;
1337
1349
}
1338
1350
return Promise . resolve ( ) ;
1339
1351
}
@@ -1356,7 +1368,7 @@ export class OAuthService extends AuthConfig {
1356
1368
this . storeIdToken ( result ) ;
1357
1369
this . storeSessionState ( sessionState ) ;
1358
1370
if ( this . clearHashAfterLogin ) {
1359
- location . hash = '' ;
1371
+ this . clearHash ( ) ;
1360
1372
}
1361
1373
this . eventsSubject . next ( new OAuthSuccessEvent ( 'token_received' ) ) ;
1362
1374
this . callOnTokenReceivedIfExists ( options ) ;
@@ -1405,7 +1417,7 @@ export class OAuthService extends AuthConfig {
1405
1417
options . onLoginError ( parts ) ;
1406
1418
}
1407
1419
if ( this . clearHashAfterLogin ) {
1408
- location . hash = '' ;
1420
+ this . clearHash ( ) ;
1409
1421
}
1410
1422
}
1411
1423
0 commit comments