@@ -288,33 +288,46 @@ export class UserAgentApplication {
288
288
* @param hash
289
289
*/
290
290
public urlContainsHash ( hash : string ) {
291
+ this . logger . verbose ( "UrlContainsHash has been called" ) ;
291
292
return UrlUtils . urlContainsHash ( hash ) ;
292
293
}
293
294
294
295
private authResponseHandler ( interactionType : InteractionType , response : AuthResponse , resolve ?: any ) : void {
296
+ this . logger . verbose ( "AuthResponseHandler has been called" ) ;
297
+
295
298
if ( interactionType === Constants . interactionTypeRedirect ) {
299
+ this . logger . verbose ( "Interaction type is redirect" ) ;
296
300
if ( this . errorReceivedCallback ) {
301
+ this . logger . verbose ( "Two callbacks were provided to handleRedirectCallback, calling success callback with response" ) ;
297
302
this . tokenReceivedCallback ( response ) ;
298
303
} else if ( this . authResponseCallback ) {
304
+ this . logger . verbose ( "One callback was provided to handleRedirectCallback, calling authResponseCallback with response" ) ;
299
305
this . authResponseCallback ( null , response ) ;
300
306
}
301
307
} else if ( interactionType === Constants . interactionTypePopup ) {
308
+ this . logger . verbose ( "Interaction type is popup, resolving" ) ;
302
309
resolve ( response ) ;
303
310
} else {
304
311
throw ClientAuthError . createInvalidInteractionTypeError ( ) ;
305
312
}
306
313
}
307
314
308
315
private authErrorHandler ( interactionType : InteractionType , authErr : AuthError , response : AuthResponse , reject ?: any ) : void {
316
+ this . logger . verbose ( "AuthErrorHandler has been called" ) ;
317
+
309
318
// set interaction_status to complete
310
319
this . cacheStorage . removeItem ( TemporaryCacheKeys . INTERACTION_STATUS ) ;
311
320
if ( interactionType === Constants . interactionTypeRedirect ) {
321
+ this . logger . verbose ( "Interaction type is redirect" ) ;
312
322
if ( this . errorReceivedCallback ) {
323
+ this . logger . verbose ( "Two callbacks were provided to handleRedirectCallback, calling error callback" ) ;
313
324
this . errorReceivedCallback ( authErr , response . accountState ) ;
314
325
} else {
326
+ this . logger . verbose ( "One callback was provided to handleRedirectCallback, calling authResponseCallback with error" ) ;
315
327
this . authResponseCallback ( authErr , response ) ;
316
328
}
317
329
} else if ( interactionType === Constants . interactionTypePopup ) {
330
+ this . logger . verbose ( "Interaction type is popup, rejecting" ) ;
318
331
reject ( authErr ) ;
319
332
} else {
320
333
throw ClientAuthError . createInvalidInteractionTypeError ( ) ;
@@ -327,6 +340,8 @@ export class UserAgentApplication {
327
340
* @param {@link (AuthenticationParameters:type) }
328
341
*/
329
342
loginRedirect ( userRequest ?: AuthenticationParameters ) : void {
343
+ this . logger . verbose ( "LoginRedirect has been called" ) ;
344
+
330
345
// validate request
331
346
const request : AuthenticationParameters = RequestUtils . validateRequest ( userRequest , true , this . clientId , Constants . interactionTypeRedirect ) ;
332
347
this . acquireTokenInteractive ( Constants . interactionTypeRedirect , true , request , null , null ) ;
@@ -339,6 +354,8 @@ export class UserAgentApplication {
339
354
* To renew idToken, please pass clientId as the only scope in the Authentication Parameters
340
355
*/
341
356
acquireTokenRedirect ( userRequest : AuthenticationParameters ) : void {
357
+ this . logger . verbose ( "AcquireTokenRedirect has been called" ) ;
358
+
342
359
// validate request
343
360
const request : AuthenticationParameters = RequestUtils . validateRequest ( userRequest , false , this . clientId , Constants . interactionTypeRedirect ) ;
344
361
this . acquireTokenInteractive ( Constants . interactionTypeRedirect , false , request , null , null ) ;
@@ -352,6 +369,8 @@ export class UserAgentApplication {
352
369
* @returns {Promise.<AuthResponse> } - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} object
353
370
*/
354
371
loginPopup ( userRequest ?: AuthenticationParameters ) : Promise < AuthResponse > {
372
+ this . logger . verbose ( "LoginPopup has been called" ) ;
373
+
355
374
// validate request
356
375
const request : AuthenticationParameters = RequestUtils . validateRequest ( userRequest , true , this . clientId , Constants . interactionTypePopup ) ;
357
376
const apiEvent : ApiEvent = this . telemetryManager . createAndStartApiEvent ( request . correlationId , API_EVENT_IDENTIFIER . LoginPopup ) ;
@@ -360,6 +379,7 @@ export class UserAgentApplication {
360
379
this . acquireTokenInteractive ( Constants . interactionTypePopup , true , request , resolve , reject ) ;
361
380
} )
362
381
. then ( ( resp ) => {
382
+ this . logger . verbose ( "Successfully logged in" ) ;
363
383
this . telemetryManager . stopAndFlushApiEvent ( request . correlationId , apiEvent , true ) ;
364
384
return resp ;
365
385
} )
@@ -652,6 +672,8 @@ export class UserAgentApplication {
652
672
* @param request
653
673
*/
654
674
ssoSilent ( request : AuthenticationParameters ) : Promise < AuthResponse > {
675
+ this . logger . verbose ( "ssoSilent has been called" ) ;
676
+
655
677
// throw an error on an empty request
656
678
if ( ! request ) {
657
679
throw ClientConfigurationError . createEmptyRequestError ( ) ;
@@ -1020,6 +1042,7 @@ export class UserAgentApplication {
1020
1042
* Default behaviour is to redirect the user to `window.location.href`.
1021
1043
*/
1022
1044
logout ( correlationId ?: string ) : void {
1045
+ this . logger . verbose ( "Logout has been called" ) ;
1023
1046
this . logoutAsync ( correlationId ) ;
1024
1047
}
1025
1048
@@ -1044,15 +1067,28 @@ export class UserAgentApplication {
1044
1067
1045
1068
const correlationIdParam = `client-request-id=${ requestCorrelationId } ` ;
1046
1069
1047
- const postLogoutQueryParam = this . getPostLogoutRedirectUri ( )
1048
- ? `&post_logout_redirect_uri=${ encodeURIComponent ( this . getPostLogoutRedirectUri ( ) ) } `
1049
- : "" ;
1070
+ let postLogoutQueryParam : string ;
1071
+ if ( this . getPostLogoutRedirectUri ( ) ) {
1072
+ postLogoutQueryParam = `&post_logout_redirect_uri=${ encodeURIComponent ( this . getPostLogoutRedirectUri ( ) ) } ` ;
1073
+ this . logger . verbose ( "redirectUri found and set" ) ;
1074
+ } else {
1075
+ postLogoutQueryParam = "" ;
1076
+ this . logger . verbose ( "No redirectUri set for app. postLogoutQueryParam is empty" ) ;
1077
+ }
1050
1078
1051
- const urlNavigate = this . authorityInstance . EndSessionEndpoint
1052
- ? `${ this . authorityInstance . EndSessionEndpoint } ?${ correlationIdParam } ${ postLogoutQueryParam } `
1053
- : `${ this . authority } oauth2/v2.0/logout?${ correlationIdParam } ${ postLogoutQueryParam } ` ;
1079
+ let urlNavigate : string ;
1080
+ if ( this . authorityInstance . EndSessionEndpoint ) {
1081
+ urlNavigate = `${ this . authorityInstance . EndSessionEndpoint } ?${ correlationIdParam } ${ postLogoutQueryParam } ` ;
1082
+ this . logger . verbose ( "EndSessionEndpoint found and urlNavigate set" ) ;
1083
+ this . logger . verbosePii ( `urlNavigate set to: ${ this . authorityInstance . EndSessionEndpoint } ` ) ;
1084
+ } else {
1085
+ urlNavigate = `${ this . authority } oauth2/v2.0/logout?${ correlationIdParam } ${ postLogoutQueryParam } ` ;
1086
+ this . logger . verbose ( "No endpoint, urlNavigate set to default" ) ;
1087
+ }
1054
1088
1055
1089
this . telemetryManager . stopAndFlushApiEvent ( requestCorrelationId , apiEvent , true ) ;
1090
+
1091
+ this . logger . verbose ( "Navigating window to urlNavigate" ) ;
1056
1092
this . navigateWindow ( urlNavigate ) ;
1057
1093
} catch ( error ) {
1058
1094
this . telemetryManager . stopAndFlushApiEvent ( requestCorrelationId , apiEvent , false , error . errorCode ) ;
@@ -1065,6 +1101,7 @@ export class UserAgentApplication {
1065
1101
* @ignore
1066
1102
*/
1067
1103
protected clearCache ( ) : void {
1104
+ this . logger . verbose ( "Clearing cache" ) ;
1068
1105
window . renewStates = [ ] ;
1069
1106
const accessTokenItems = this . cacheStorage . getAllAccessTokens ( Constants . clientId , Constants . homeAccountIdentifier ) ;
1070
1107
for ( let i = 0 ; i < accessTokenItems . length ; i ++ ) {
@@ -1073,6 +1110,7 @@ export class UserAgentApplication {
1073
1110
this . cacheStorage . resetCacheItems ( ) ;
1074
1111
// state not being sent would mean this call may not be needed; check later
1075
1112
this . cacheStorage . clearMsalCookie ( ) ;
1113
+ this . logger . verbose ( "Cache cleared" ) ;
1076
1114
}
1077
1115
1078
1116
/**
@@ -1082,11 +1120,13 @@ export class UserAgentApplication {
1082
1120
* @param accessToken
1083
1121
*/
1084
1122
protected clearCacheForScope ( accessToken : string ) {
1123
+ this . logger . verbose ( "Clearing access token from cache" ) ;
1085
1124
const accessTokenItems = this . cacheStorage . getAllAccessTokens ( Constants . clientId , Constants . homeAccountIdentifier ) ;
1086
1125
for ( let i = 0 ; i < accessTokenItems . length ; i ++ ) {
1087
1126
const token = accessTokenItems [ i ] ;
1088
1127
if ( token . value . accessToken === accessToken ) {
1089
1128
this . cacheStorage . removeItem ( JSON . stringify ( token . key ) ) ;
1129
+ this . logger . verbosePii ( `Access token removed: ${ token . key } ` ) ;
1090
1130
}
1091
1131
}
1092
1132
}
0 commit comments