@@ -106,6 +106,12 @@ export class PublicClientApplication {
106
106
this . config . auth . authority ,
107
107
this . networkClient
108
108
) ;
109
+
110
+ const { location : { hash } } = window ;
111
+ if ( StringUtils . isEmpty ( hash ) ) {
112
+ // There is no hash - assume we are in clean state and clear any current request data.
113
+ this . browserStorage . cleanRequest ( ) ;
114
+ }
109
115
}
110
116
111
117
// #region Redirect Flow
@@ -156,19 +162,19 @@ export class PublicClientApplication {
156
162
*/
157
163
private async handleRedirectResponse ( ) : Promise < AuthenticationResult > {
158
164
// Get current location hash from window or cache.
159
- const { location : { hash} } = window ;
165
+ const { location : { hash } } = window ;
160
166
const cachedHash = this . browserStorage . getItem ( this . browserStorage . generateCacheKey ( TemporaryCacheKeys . URL_HASH ) , CacheSchemaType . TEMPORARY ) as string ;
161
167
const isResponseHash = UrlString . hashContainsKnownProperties ( hash ) ;
162
168
const loginRequestUrl = this . browserStorage . getItem ( this . browserStorage . generateCacheKey ( TemporaryCacheKeys . ORIGIN_URI ) , CacheSchemaType . TEMPORARY ) as string ;
163
169
const currentUrl = BrowserUtils . getCurrentUri ( ) ;
164
- if ( loginRequestUrl === currentUrl ) {
170
+ if ( loginRequestUrl === currentUrl || ! this . config . auth . navigateToLoginRequestUrl ) {
165
171
// We don't need to navigate - check for hash and prepare to process
166
172
if ( isResponseHash ) {
167
173
BrowserUtils . clearHash ( ) ;
168
174
return this . handleHash ( hash ) ;
169
175
} else {
170
176
// Loaded page with no valid hash - pass in the value retrieved from cache, or null/empty string
171
- return this . handleHash ( ` ${ cachedHash } ` ) ;
177
+ return this . handleHash ( cachedHash ) ;
172
178
}
173
179
}
174
180
@@ -184,39 +190,27 @@ export class PublicClientApplication {
184
190
// Navigate to target url
185
191
BrowserUtils . navigateWindow ( loginRequestUrl , true ) ;
186
192
}
187
- return null ;
188
- }
189
-
190
- if ( ! isResponseHash ) {
191
- // Loaded page with no valid hash - pass in the value retrieved from cache, or null/empty string
192
- return this . handleHash ( cachedHash ) ;
193
- }
194
-
195
- if ( ! this . config . auth . navigateToLoginRequestUrl ) {
196
- // We don't need to navigate - check for hash and prepare to process
197
- BrowserUtils . clearHash ( ) ;
198
- return this . handleHash ( hash ) ;
199
193
}
200
194
201
195
return null ;
202
196
}
203
197
204
198
/**
205
- * Checks if hash exists and handles in window. Otherwise, cancel any current requests and continue.
199
+ * Checks if hash exists and handles in window.
206
200
* @param responseHash
207
201
* @param interactionHandler
208
202
*/
209
203
private async handleHash ( responseHash : string ) : Promise < AuthenticationResult > {
204
+ // There is no hash - return null.
205
+ if ( StringUtils . isEmpty ( responseHash ) ) {
206
+ return null ;
207
+ }
208
+
209
+ // Hash contains known properties - handle and return in callback
210
210
const currentAuthority = this . browserStorage . getCachedAuthority ( ) ;
211
211
const authClient = await this . createAuthCodeClient ( currentAuthority ) ;
212
212
const interactionHandler = new RedirectHandler ( authClient , this . browserStorage ) ;
213
- if ( ! StringUtils . isEmpty ( responseHash ) ) {
214
- // Hash contains known properties - handle and return in callback
215
- return interactionHandler . handleCodeResponse ( responseHash , this . browserCrypto ) ;
216
- }
217
- // There is no hash - assume we are in clean state and clear any current request data.
218
- this . browserStorage . cleanRequest ( ) ;
219
- return null ;
213
+ return interactionHandler . handleCodeResponse ( responseHash , this . browserCrypto ) ;
220
214
}
221
215
222
216
/**
0 commit comments