Skip to content

Commit 7d32810

Browse files
Add changes that should re-enable iframe based silent refresh
1 parent 3b13ef9 commit 7d32810

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

src/app/core/auth.service.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { Router } from '@angular/router';
3-
import { OAuthErrorEvent, OAuthService } from 'angular-oauth2-oidc';
3+
import { OAuthErrorEvent, OAuthService, OAuthEvent, TokenResponse } from 'angular-oauth2-oidc';
44
import { BehaviorSubject, combineLatest, Observable, ReplaySubject } from 'rxjs';
55
import { filter, map } from 'rxjs/operators';
66

@@ -76,10 +76,6 @@ export class AuthService {
7676
.pipe(filter(e => ['session_terminated', 'session_error'].includes(e.type)))
7777
.subscribe(e => this.navigateToLoginPage());
7878

79-
// This *does* work with v9.0.0 as it detects code+pkce flow and sets up
80-
// refreshToken() calls that require offline_access, instead of actually
81-
// calling silentRefresh, which would fail because of this issue:
82-
// https://github.com/manfredsteyer/angular-oauth2-oidc/issues/600
8379
this.oauthService.setupAutomaticSilentRefresh();
8480
}
8581

@@ -164,15 +160,14 @@ export class AuthService {
164160
.catch(() => this.isDoneLoadingSubject$.next(true));
165161
}
166162

167-
private startWithRefresh() {
163+
private startWithRefresh(): Promise<TokenResponse | OAuthEvent> {
168164
if (this.oauthService.getRefreshToken()) {
169165
console.log('Found a refresh token, trying to use it.');
170166
return this.oauthService.refreshToken();
171167
}
172168

173-
// No silent refresh via iframe is supported for code flow yet.
174-
// See also: https://github.com/manfredsteyer/angular-oauth2-oidc/issues/600
175-
return Promise.reject();
169+
console.log('Found no refresh token, trying iframe based refresh');
170+
return this.oauthService.silentRefresh();
176171
}
177172

178173
public login(targetUrl?: string) {
@@ -182,13 +177,7 @@ export class AuthService {
182177
}
183178

184179
public logout() { this.oauthService.logOut(); }
185-
public refresh() {
186-
// Silent refresh via iframe is not supported (yet?) for the code+pkce flow.
187-
// See also: https://github.com/manfredsteyer/angular-oauth2-oidc/issues/600
188-
// this.oauthService.silentRefresh();
189-
// So for now we do this instead:
190-
this.oauthService.refreshToken();
191-
}
180+
public refresh() { this.oauthService.silentRefresh(); }
192181
public hasValidToken() { return this.oauthService.hasValidAccessToken(); }
193182

194183
// These normally won't be exposed from a service like this, but

0 commit comments

Comments
 (0)