question

paf2021 avatar image
0 Votes"
paf2021 asked azure-cxp-api edited

MSAL2 AcquireTokenSilent not refreshing tokens correctly

Hello,

I have the following code in my interceptor for every http call. To obtain the accessToken, I call acquireTokenSilent and it works OK if the token is valid. If the token has expired it returns the following error:

InteractionRequiredAuthError: login_required: AADSTS50058: A silent sign-in request was sent but none of the currently signed in user(s) match the requested login hint.


Here is my sample code (where mailUser is the username of the logged in user in the application):

 const silentRequest = {
     scopes: scopes,
     account: account,
     loginHint: mailUser
 };
    
     return this.authService.acquireTokenSilent(silentRequest)
         .pipe(
             catchError((error) => {
                 if (error.name === "InteractionRequiredAuthError") {
                     **?????**
                 }
               return EMPTY;
             }),
             switchMap((result: AuthenticationResult) => {
                 console.log("result.accessToken}");
             })
         );



How should I obtain the token in case of said error? I tried calling acquireTokenRedirect but it keeps refreshing the page on loop giving the same error

Thanks in advance






azure-ad-msal
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @paf2021 , we are investigating your issue and will update you shortly.

Best,
James

1 Vote 1 ·

Hi @paf2021 , what is your app type, and what flow are you trying to achieve? ( auth code, implicit flow) What is the exact code that you used when you tried using acquireTokenRedirect?

Best,
James

0 Votes 0 ·

0 Answers