Skip to content
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

force refresh session, new API #730

Merged
merged 4 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 11 additions & 0 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export class OidcSecurityService {
this.loginService.login(authOptions);
}

forceRefreshSession() {
return 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) {
Expand Down