diff --git a/package-lock.json b/package-lock.json index 9f7840f1..763488e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "starter", - "version": "9.3.0", + "version": "10.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 6f0bce0f..417c85c1 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -102,6 +102,7 @@ export class OAuthService extends AuthConfig implements OnDestroy { protected accessTokenTimeoutSubscription: Subscription; protected idTokenTimeoutSubscription: Subscription; protected tokenReceivedSubscription: Subscription; + protected automaticRefreshSubscription: Subscription; protected sessionCheckEventListener: EventListener; protected jwksUri: string; protected sessionCheckTimer: any; @@ -222,7 +223,8 @@ export class OAuthService extends AuthConfig implements OnDestroy { noPrompt = true ): void { let shouldRunSilentRefresh = true; - this.events + this.clearAutomaticRefreshTimer(); + this.automaticRefreshSubscription = this.events .pipe( tap(e => { if (e.type === 'token_received') { @@ -448,6 +450,7 @@ export class OAuthService extends AuthConfig implements OnDestroy { public stopAutomaticRefresh() { this.clearAccessTokenTimer(); this.clearIdTokenTimer(); + this.clearAutomaticRefreshTimer(); } protected clearAccessTokenTimer(): void { @@ -462,6 +465,12 @@ export class OAuthService extends AuthConfig implements OnDestroy { } } + protected clearAutomaticRefreshTimer(): void { + if (this.automaticRefreshSubscription) { + this.automaticRefreshSubscription.unsubscribe(); + } + } + protected calcTimeout(storedAt: number, expiration: number): number { const now = Date.now(); const delta = diff --git a/projects/sample/src/app/home/home.component.html b/projects/sample/src/app/home/home.component.html index b1247c82..27a6b657 100644 --- a/projects/sample/src/app/home/home.component.html +++ b/projects/sample/src/app/home/home.component.html @@ -109,5 +109,13 @@

Further Actions

+ + + + diff --git a/projects/sample/src/app/home/home.component.ts b/projects/sample/src/app/home/home.component.ts index 3b7f334b..a6f5e431 100644 --- a/projects/sample/src/app/home/home.component.ts +++ b/projects/sample/src/app/home/home.component.ts @@ -86,6 +86,14 @@ export class HomeComponent implements OnInit { this.oauthService.loadUserProfile().then(up => (this.userProfile = up)); } + startAutomaticRefresh(): void { + this.oauthService.setupAutomaticSilentRefresh(); + } + + stopAutomaticRefresh(): void { + this.oauthService.stopAutomaticRefresh(); + } + get givenName() { var claims = this.oauthService.getIdentityClaims(); if (!claims) return null;