MSAL2 AcquireTokenSilent not refreshing tokens correctly

Patricia 1 Reputation point
2021-03-24T16:45:56.277+00:00

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

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,458 questions
{count} votes