File tree 3 files changed +17
-6
lines changed
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,9 @@ export const authConfig: AuthConfig = {
4
4
issuer : 'https://demo.identityserver.io' ,
5
5
clientId : 'spa' , // The "Auth Code + PKCE" client
6
6
responseType : 'code' ,
7
- useSilentRefresh : true , // Only needed for Code Flow
8
7
redirectUri : window . location . origin + '/index.html' ,
9
8
silentRefreshRedirectUri : window . location . origin + '/silent-refresh.html' ,
10
- scope : 'openid profile email api' ,
9
+ scope : 'openid profile email api' , // Ask offline_access to support refresh token refreshes
11
10
silentRefreshTimeout : 5000 , // For faster testing
12
11
timeoutFactor : 0.25 , // For faster testing
13
12
sessionChecksEnabled : true ,
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ export class AuthService {
106
106
// 2. SILENT LOGIN:
107
107
// Try to log in via a refresh because then we can prevent
108
108
// needing to redirect the user:
109
- return this . startWithRefresh ( )
109
+ return this . tryNoPromptRefresh ( )
110
110
. then ( ( ) => Promise . resolve ( ) )
111
111
. catch ( result => {
112
112
// Subset of situations from https://openid.net/specs/openid-connect-core-1_0.html#AuthError
@@ -160,7 +160,7 @@ export class AuthService {
160
160
. catch ( ( ) => this . isDoneLoadingSubject$ . next ( true ) ) ;
161
161
}
162
162
163
- private startWithRefresh ( ) : Promise < TokenResponse | OAuthEvent > {
163
+ private tryNoPromptRefresh ( ) : Promise < TokenResponse | OAuthEvent > {
164
164
if ( this . oauthService . getRefreshToken ( ) ) {
165
165
console . log ( 'Found a refresh token, trying to use it.' ) ;
166
166
return this . oauthService . refreshToken ( ) ;
@@ -177,7 +177,7 @@ export class AuthService {
177
177
}
178
178
179
179
public logout ( ) { this . oauthService . logOut ( ) ; }
180
- public refresh ( ) { this . oauthService . silentRefresh ( ) ; }
180
+ public refresh ( ) { this . tryNoPromptRefresh ( ) ; }
181
181
public hasValidToken ( ) { return this . oauthService . hasValidAccessToken ( ) ; }
182
182
183
183
// These normally won't be exposed from a service like this, but
Original file line number Diff line number Diff line change 2
2
< html >
3
3
< body >
4
4
< script >
5
- parent . postMessage ( location . hash , location . origin ) ;
5
+ console . log ( "The silent-refresh.html file was loaded and now posting to the parent." ) ;
6
+
7
+ // For code flow with IdentityServer4 the redirect will contain the new code in
8
+ // the location.search. However, the oauth library expects it in the hash fragment
9
+ // so we need to "fake" that.
10
+ //
11
+ // We can't just set `silentRefreshMessagePrefix` on AuthConfig, because the normal
12
+ // redirect after interactive login *does* use the hash fragment, so we'd break that.
13
+ //
14
+ // See also: https://github.com/manfredsteyer/angular-oauth2-oidc/issues/777
15
+ const fakeHashFragment = location . search . replace ( / ^ \? / , "#" ) ;
16
+
17
+ parent . postMessage ( fakeHashFragment , location . origin ) ;
6
18
</ script >
7
19
</ body >
8
20
</ html >
You can’t perform that action at this time.
0 commit comments