@@ -630,6 +630,8 @@ export class UserAgentApplication {
630
630
*
631
631
*/
632
632
acquireTokenSilent ( userRequest : AuthenticationParameters ) : Promise < AuthResponse > {
633
+ this . logger . verbose ( "AcquireTokenSilent has been called" ) ;
634
+
633
635
// validate the request
634
636
const request = RequestUtils . validateRequest ( userRequest , false , this . clientId , Constants . interactionTypeSilent ) ;
635
637
const apiEvent : ApiEvent = this . telemetryManager . createAndStartApiEvent ( request . correlationId , API_EVENT_IDENTIFIER . AcquireTokenSilent ) ;
@@ -641,21 +643,31 @@ export class UserAgentApplication {
641
643
WindowUtils . blockReloadInHiddenIframes ( ) ;
642
644
643
645
const scope = request . scopes . join ( " " ) . toLowerCase ( ) ;
646
+ this . logger . verbosePii ( `Serialized scopes: ${ scope } ` ) ;
644
647
645
648
// if the developer passes an account, give that account the priority
646
- const account : Account = request . account || this . getAccount ( ) ;
649
+ let account : Account ;
650
+ if ( request . account ) {
651
+ account = request . account ;
652
+ this . logger . verbose ( "Account set from request" ) ;
653
+ } else {
654
+ account = this . getAccount ( ) ;
655
+ this . logger . verbose ( "Account set from MSAL Cache" ) ;
656
+ }
647
657
648
- // extract if there is an adalIdToken stashed in the cache
658
+ // Extract adalIdToken if stashed in the cache to allow for seamless ADAL to MSAL migration
649
659
const adalIdToken = this . cacheStorage . getItem ( Constants . adalIdToken ) ;
650
660
651
- // if there is no account logged in and no login_hint/sid is passed in the request
661
+ // In the event of no account being passed in the config, no session id, and no pre-existing adalIdToken, user will need to log in
652
662
if ( ! account && ! ( request . sid || request . loginHint ) && StringUtils . isEmpty ( adalIdToken ) ) {
653
663
this . logger . info ( "User login is required" ) ;
664
+ // The promise rejects with a UserLoginRequiredError, which should be caught and user should be prompted to log in interactively
654
665
return reject ( ClientAuthError . createUserLoginRequiredError ( ) ) ;
655
666
}
656
667
657
668
// set the response type based on the current cache status / scopes set
658
669
const responseType = this . getTokenType ( account , request . scopes , true ) ;
670
+ this . logger . verbose ( `Response type: ${ responseType } ` ) ;
659
671
660
672
// create a serverAuthenticationRequest populating the `queryParameters` to be sent to the Server
661
673
const serverAuthenticationRequest = new ServerRequestParameters (
@@ -668,23 +680,30 @@ export class UserAgentApplication {
668
680
request . correlationId ,
669
681
) ;
670
682
683
+ this . logger . verbose ( "Finished building server authentication request" ) ;
684
+
671
685
// populate QueryParameters (sid/login_hint) and any other extraQueryParameters set by the developer
672
686
if ( ServerRequestParameters . isSSOParam ( request ) || account ) {
673
687
serverAuthenticationRequest . populateQueryParams ( account , request , null , true ) ;
688
+ this . logger . verbose ( "Query parameters populated from existing SSO or account" ) ;
674
689
}
675
690
// if user didn't pass login_hint/sid and adal's idtoken is present, extract the login_hint from the adalIdToken
676
691
else if ( ! account && ! StringUtils . isEmpty ( adalIdToken ) ) {
677
692
// if adalIdToken exists, extract the SSO info from the same
678
693
const adalIdTokenObject = TokenUtils . extractIdToken ( adalIdToken ) ;
679
- this . logger . verbose ( "ADAL's idToken exists. Extracting login information from ADAL's idToken " ) ;
694
+ this . logger . verbose ( "ADAL's idToken exists. Extracting login information from ADAL's idToken to populate query parameters " ) ;
680
695
serverAuthenticationRequest . populateQueryParams ( account , null , adalIdTokenObject , true ) ;
681
696
}
697
+ else {
698
+ this . logger . verbose ( "No additional query parameters added" ) ;
699
+ }
682
700
683
701
const userContainedClaims = request . claimsRequest || serverAuthenticationRequest . claimsValue ;
684
702
685
703
let authErr : AuthError ;
686
704
let cacheResultResponse ;
687
705
706
+ // If request.forceRefresh is set to true, force a request for a new token instead of getting it from the cache
688
707
if ( ! userContainedClaims && ! request . forceRefresh ) {
689
708
try {
690
709
cacheResultResponse = this . getCachedToken ( serverAuthenticationRequest , account ) ;
@@ -695,7 +714,7 @@ export class UserAgentApplication {
695
714
696
715
// resolve/reject based on cacheResult
697
716
if ( cacheResultResponse ) {
698
- this . logger . info ( "Token is already in cache for scope:" + scope ) ;
717
+ this . logger . verbose ( "Token is already in cache for scope: " + scope ) ;
699
718
resolve ( cacheResultResponse ) ;
700
719
return null ;
701
720
}
@@ -708,18 +727,20 @@ export class UserAgentApplication {
708
727
else {
709
728
let logMessage ;
710
729
if ( userContainedClaims ) {
711
- logMessage = "Skipped cache lookup since claims were given. " ;
730
+ logMessage = "Skipped cache lookup since claims were given" ;
712
731
} else if ( request . forceRefresh ) {
713
732
logMessage = "Skipped cache lookup since request.forceRefresh option was set to true" ;
714
733
} else {
715
- logMessage = "Token is not in cache for scope:" + scope ;
734
+ logMessage = "Token is not in cache for scope: " + scope ;
716
735
}
717
736
this . logger . verbose ( logMessage ) ;
718
737
719
- // Cache result can return null if cache is empty. In that case, set authority to default value if no authority is passed to the api .
738
+ // Cache result can return null if cache is empty. In that case, set authority to default value if no authority is passed to the API .
720
739
if ( ! serverAuthenticationRequest . authorityInstance ) {
721
740
serverAuthenticationRequest . authorityInstance = request . authority ? AuthorityFactory . CreateInstance ( request . authority , this . config . auth . validateAuthority ) : this . authorityInstance ;
722
741
}
742
+ this . logger . verbosePii ( `Authority instance: ${ serverAuthenticationRequest . authority } ` ) ;
743
+
723
744
// cache miss
724
745
725
746
// start http event
@@ -729,6 +750,8 @@ export class UserAgentApplication {
729
750
* refresh attempt with iframe
730
751
* Already renewing for this scope, callback when we get the token.
731
752
*/
753
+ this . logger . verbose ( "Authority has been updated with endpoint discovery response" ) ;
754
+
732
755
if ( window . activeRenewals [ requestSignature ] ) {
733
756
this . logger . verbose ( "Renew token for scope and authority: " + requestSignature + " is in progress. Registering callback" ) ;
734
757
// Active renewals contains the state for each renewal.
@@ -740,23 +763,24 @@ export class UserAgentApplication {
740
763
* App uses idToken to send to api endpoints
741
764
* Default scope is tracked as clientId to store this token
742
765
*/
743
- this . logger . verbose ( "renewing idToken" ) ;
766
+ this . logger . verbose ( "Renewing idToken" ) ;
744
767
this . silentLogin = true ;
745
768
this . renewIdToken ( requestSignature , resolve , reject , account , serverAuthenticationRequest ) ;
746
769
} else {
747
770
// renew access token
748
- this . logger . verbose ( "renewing accesstoken " ) ;
771
+ this . logger . verbose ( "Renewing access token " ) ;
749
772
this . renewToken ( requestSignature , resolve , reject , account , serverAuthenticationRequest ) ;
750
773
}
751
774
}
752
775
} ) . catch ( ( err ) => {
753
- this . logger . error ( err ) ;
776
+ this . logger . warning ( "Could not resolve endpoints" ) ;
754
777
reject ( ClientAuthError . createEndpointResolutionError ( err . toString ( ) ) ) ;
755
778
return null ;
756
779
} ) ;
757
780
}
758
781
} )
759
782
. then ( res => {
783
+ this . logger . verbose ( "Successfully acquired token" ) ;
760
784
this . telemetryManager . stopAndFlushApiEvent ( request . correlationId , apiEvent , true ) ;
761
785
return res ;
762
786
} )
0 commit comments