1
1
import { Injectable } from '@angular/core' ;
2
2
import { Router } from '@angular/router' ;
3
- import { OAuthErrorEvent , OAuthService } from 'angular-oauth2-oidc' ;
3
+ import { OAuthErrorEvent , OAuthService , OAuthEvent , TokenResponse } from 'angular-oauth2-oidc' ;
4
4
import { BehaviorSubject , combineLatest , Observable , ReplaySubject } from 'rxjs' ;
5
5
import { filter , map } from 'rxjs/operators' ;
6
6
@@ -76,10 +76,6 @@ export class AuthService {
76
76
. pipe ( filter ( e => [ 'session_terminated' , 'session_error' ] . includes ( e . type ) ) )
77
77
. subscribe ( e => this . navigateToLoginPage ( ) ) ;
78
78
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
83
79
this . oauthService . setupAutomaticSilentRefresh ( ) ;
84
80
}
85
81
@@ -110,7 +106,7 @@ export class AuthService {
110
106
// 2. SILENT LOGIN:
111
107
// Try to log in via a refresh because then we can prevent
112
108
// needing to redirect the user:
113
- return this . startWithRefresh ( )
109
+ return this . tryNoPromptRefresh ( )
114
110
. then ( ( ) => Promise . resolve ( ) )
115
111
. catch ( result => {
116
112
// Subset of situations from https://openid.net/specs/openid-connect-core-1_0.html#AuthError
@@ -164,15 +160,14 @@ export class AuthService {
164
160
. catch ( ( ) => this . isDoneLoadingSubject$ . next ( true ) ) ;
165
161
}
166
162
167
- private startWithRefresh ( ) {
163
+ private tryNoPromptRefresh ( ) : Promise < TokenResponse | OAuthEvent > {
168
164
if ( this . oauthService . getRefreshToken ( ) ) {
169
165
console . log ( 'Found a refresh token, trying to use it.' ) ;
170
166
return this . oauthService . refreshToken ( ) ;
171
167
}
172
168
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 ( ) ;
176
171
}
177
172
178
173
public login ( targetUrl ?: string ) {
@@ -182,13 +177,7 @@ export class AuthService {
182
177
}
183
178
184
179
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 . tryNoPromptRefresh ( ) ; }
192
181
public hasValidToken ( ) { return this . oauthService . hasValidAccessToken ( ) ; }
193
182
194
183
// These normally won't be exposed from a service like this, but
0 commit comments