Skip to content

Added option to set up silent refresh only for certain type of token. #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,14 @@ export class OAuthService extends AuthConfig {
* about to expire.
* @param params Additional parameter to pass
*/
public setupAutomaticSilentRefresh(params: object = {}) {
public setupAutomaticSilentRefresh(params: object = {}, listenTo?: 'access_token' | 'id_token' | 'any') {
this.events.pipe(filter(e => e.type === 'token_expires')).subscribe(e => {
this.silentRefresh(params).catch(_ => {
this.debug('Automatic silent refresh did not work');
});
const event = e as OAuthInfoEvent;
if ( listenTo == null || listenTo === 'any' || event.info === listenTo ) {
this.silentRefresh(params).catch(_ => {
this.debug('Automatic silent refresh did not work');
});
}
});

this.restartRefreshTimerIfStillLoggedIn();
Expand Down Expand Up @@ -942,12 +945,12 @@ export class OAuthService extends AuthConfig {
break;
case 'changed':
this.ngZone.run(() => {
this.handleSessionChange()
this.handleSessionChange();
});
break;
case 'error':
this.ngZone.run(() => {
this.handleSessionError()
this.ngZone.run(() => {
this.handleSessionError();
});
break;
}
Expand Down Expand Up @@ -1761,7 +1764,7 @@ export class OAuthService extends AuthConfig {
logoutUrl =
this.logoutUrl +
(this.logoutUrl.indexOf('?') > -1 ? '&' : '?') +
params.toString()
params.toString();
}
location.href = logoutUrl;
}
Expand Down