Skip to content

Commit 0274cf5

Browse files
Merge pull request #462 from martin1cerny/master
Added option to set up silent refresh only for certain type of token.
2 parents 2863669 + 940f315 commit 0274cf5

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

projects/lib/src/oauth-service.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,14 @@ export class OAuthService extends AuthConfig {
161161
* about to expire.
162162
* @param params Additional parameter to pass
163163
*/
164-
public setupAutomaticSilentRefresh(params: object = {}) {
164+
public setupAutomaticSilentRefresh(params: object = {}, listenTo?: 'access_token' | 'id_token' | 'any') {
165165
this.events.pipe(filter(e => e.type === 'token_expires')).subscribe(e => {
166-
this.silentRefresh(params).catch(_ => {
167-
this.debug('Automatic silent refresh did not work');
168-
});
166+
const event = e as OAuthInfoEvent;
167+
if ( listenTo == null || listenTo === 'any' || event.info === listenTo ) {
168+
this.silentRefresh(params).catch(_ => {
169+
this.debug('Automatic silent refresh did not work');
170+
});
171+
}
169172
});
170173

171174
this.restartRefreshTimerIfStillLoggedIn();
@@ -942,12 +945,12 @@ export class OAuthService extends AuthConfig {
942945
break;
943946
case 'changed':
944947
this.ngZone.run(() => {
945-
this.handleSessionChange()
948+
this.handleSessionChange();
946949
});
947950
break;
948951
case 'error':
949-
this.ngZone.run(() => {
950-
this.handleSessionError()
952+
this.ngZone.run(() => {
953+
this.handleSessionError();
951954
});
952955
break;
953956
}
@@ -1761,7 +1764,7 @@ export class OAuthService extends AuthConfig {
17611764
logoutUrl =
17621765
this.logoutUrl +
17631766
(this.logoutUrl.indexOf('?') > -1 ? '&' : '?') +
1764-
params.toString()
1767+
params.toString();
17651768
}
17661769
location.href = logoutUrl;
17671770
}

0 commit comments

Comments
 (0)