From 25b26eaf1a1d6bf9c3dfa71329a3647fbe6addd3 Mon Sep 17 00:00:00 2001 From: damienbod Date: Wed, 13 May 2020 20:52:43 +0200 Subject: [PATCH 1/4] adding a forceRefreshSession --- .../src/lib/callback/callback.service.ts | 24 +++++++++++++++++++ .../src/lib/oidc.security.service.ts | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/projects/angular-auth-oidc-client/src/lib/callback/callback.service.ts b/projects/angular-auth-oidc-client/src/lib/callback/callback.service.ts index d290ea8ec..0c1201e3a 100644 --- a/projects/angular-auth-oidc-client/src/lib/callback/callback.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/callback/callback.service.ts @@ -54,6 +54,30 @@ export class CallbackService { return callback$.pipe(tap(() => this.stsCallbackInternal$.next())); } + refreshSession() { + const idToken = this.authStateService.getIdToken(); + const isSilentRenewRunning = this.flowsDataService.isSilentRenewRunning(); + const userDataFromStore = this.userService.getUserDataFromStore(); + + this.loggerService.logDebug( + `Checking: silentRenewRunning: ${isSilentRenewRunning} id_token: ${!!idToken} userData: ${!!userDataFromStore}` + ); + + const shouldBeExecuted = userDataFromStore && !isSilentRenewRunning && idToken; + + if (!shouldBeExecuted) { + return of(null); + } + + this.flowsDataService.setSilentRenewRunning(); + + if (this.flowHelper.isCurrentFlowCodeFlowWithRefeshTokens()) { + // Refresh Session using Refresh tokens + return this.refreshSessionWithRefreshTokens(); + } + + return this.refreshSessionWithIframe(); + } startTokenValidationPeriodically(repeatAfterSeconds: number) { if (!!this.runTokenValidationRunning || !this.configurationProvider.openIDConfiguration.silentRenew) { return; diff --git a/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts b/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts index 286e6718b..068d0eee8 100644 --- a/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts @@ -123,6 +123,10 @@ export class OidcSecurityService { this.loginService.login(authOptions); } + forceRefreshSession() { + this.callbackService.refreshSession(); + } + // The refresh token and and the access token are revoked on the server. If the refresh token does not exist // only the access token is revoked. Then the logout run. logoffAndRevokeTokens(urlHandler?: (url: string) => any) { From 5ba5be946882b69d14bc896bab85134db724a024 Mon Sep 17 00:00:00 2001 From: damienbod Date: Wed, 13 May 2020 21:15:32 +0200 Subject: [PATCH 2/4] updating refresh session --- .../angular-auth-oidc-client/src/lib/oidc.security.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts b/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts index 068d0eee8..4344915c3 100644 --- a/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts @@ -124,7 +124,7 @@ export class OidcSecurityService { } forceRefreshSession() { - this.callbackService.refreshSession(); + return this.callbackService.refreshSession(); } // The refresh token and and the access token are revoked on the server. If the refresh token does not exist From 808c60deb436cbca86dbd96bb207fee9257cc18e Mon Sep 17 00:00:00 2001 From: damienbod Date: Wed, 13 May 2020 21:21:55 +0200 Subject: [PATCH 3/4] Ad some docs for the refresh session --- docs/public-api.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/public-api.md b/docs/public-api.md index d8e95d6f7..7d97d1b46 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -135,3 +135,14 @@ This makes it possible to manage your own tokens. ## getEndSessionUrl(): string | null Creates the ens session URL which can be used to implement youe own custom server logout. + +## forceRefreshSession(): Observable + +Makes it possible to refresh the tokens at any time you require. + +``` +refreshSession() { + this.oidcSecurityService.forceRefreshSession() + .subscribe((result) => console.log(result)); + } +``` From 7376f983a46992c1ef7fe2a1634233b0c394ea40 Mon Sep 17 00:00:00 2001 From: damienbod Date: Wed, 13 May 2020 21:26:10 +0200 Subject: [PATCH 4/4] updating change log --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8149f2a45..9d9e5effa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ ## Angular Lib for OpenID Connect/OAuth2 Changelog -### 2020-05-13 Version 11.1.0 +### 2020-05-14 Version 11.1.0 - Eager loading of well known endpoints can be configured: Made it possible to load the well known endpoints late (per configuration) +- make it possible to force a session refresh ### 2020-05-12 Version 11.0.2