question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MsalClientException during AcquireTokenSilentAsync with forcerefresh true

See original GitHub issue

name: Bug report about: MsalClientException during AcquireTokenSilentAsync with forcerefresh true

Which Version of MSAL are you using ? Note that to get help, you need to run the latest preview or non-preview version For ADAL, please log issues to https://github.com/AzureAD/azure-activedirectory-library-for-dotnet

v2.5.0-preview

Which platform has the issue?

net45

What authentication flow has the issue?

  • Desktop
    • Interactive
    • Integrated Windows Auth
    • Username / Password
    • Device code flow (browserless)
  • Mobile
    • Xamarin.iOS
    • Xamarin.Android
    • UWP
  • Web App
    • Authorization code
    • OBO
  • Web API
    • OBO
  • Daemon App
    • Client credentials

Other? - please describe;

What is the identity provider ?

  • Azure AD
  • Azure AD B2C

If B2C, what social identity did you use?

Repro

public static async Task<AuthenticationResult> AcquireTokenWithPromptAsync(string resource, string tenant)
        {
            string authority = $"{ProductionAuthority}/{tenant}";
            string[] scopes = { resource + ".default" };
            string clientId = Client;
            var app = new PublicClientApplication(clientId: clientId, authority: authority, userTokenCache: TokenCacheHelper.GetUserCache());

            return await app.AcquireTokenAsync(scopes).ConfigureAwait(false);
        }

        public static async Task<AuthenticationResult> AcquireTokenSilentAsync(string resource, string tenant, string userId)
        {
            string authority = $"{ProductionAuthority}/{tenant}";
            string[] scopes = { resource + ".default" };
            string clientId = Client;
            AuthenticationResult result = null;
            var app = new PublicClientApplication(clientId: clientId, authority: authority, userTokenCache: TokenCacheHelper.GetUserCache());
            var account = await app.GetAccountAsync(userId).ConfigureAwait(false);
            result = await app.AcquireTokenSilentAsync(scopes, account, authority, true).ConfigureAwait(false);
            return result;
        }

var authResult = await AcquireTokenWithPromptAsync("https://management.azure.com", "Common");

// suppose the home tenantId for the user is foo and it is also part of another tenant with tenantId bar

// this call works and get a token for foo
var result = await AcquireTokenSilentAsync("https://graph.microsoft.com/", foo, authResult.Account.HomeAccountId.Identifier).ConfigureAwait(false);

// this one fails and throws an exception
var result = await AcquireTokenSilentAsync("https://graph.microsoft.com/", bar, authResult.Account.HomeAccountId.Identifier).ConfigureAwait(false);

Expected behavior A token for the requested tenant

Actual behavior An exception - Microsoft.Identity.Client.MsalClientException: The cache contains multiple tokens satisfying the requirements. Try to clear token cache at Microsoft.Identity.Client.TokenCache.FindAccessTokenCommon(AuthenticationRequestParameters requestParams, String preferredEnvironmentAlias, ISet`1 environmentAliases) at Microsoft.Identity.Client.TokenCache.<FindAccessTokenAsync>d__47.MoveNext()

If force refresh is set to false, then the call returns a token for the home tenant.

Possible Solution

Additional context/ Logs / Screenshots Add any other context about the problem here, such as logs and screebshots. Logging is described at https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/logging

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ferronswcommented, Apr 16, 2019

@jennyf19 @jmprieur this problem does not occur in v3.0.4.

0reactions
jmprieurcommented, Apr 16, 2019

Thanks for confirming, @ferronsw

Read more comments on GitHub >

github_iconTop Results From Across the Web

ClientApplicationBase.AcquireTokenSilentAsync Method
This means that an access token with more scopes than requested could be returned as well. If the access token is expired or...
Read more >
PublicClientApplication Class
This is the entry point for developer to create public native applications and make API calls to acquire tokens. Client ID: The clientID...
Read more >
acquireTokenSilentAsync: The signed in account does not ...
The signed in account does not match with the provided account. (Error code current_account_mismatch, from acquireTokenSilentAsync).
Read more >
PublicClientApplication (msal 0.1.3 API) - javadoc.io
This is the entry point for developer to create public native applications and make API calls to acquire tokens. Client ID: The clientID...
Read more >
netFramework/Microsoft.Identity.Client.xml 3.2.0
MsalClientException ">Thrown if the application was configured with an ... <param name="forceRefresh">If <c>true</c>, ignore any access token in the user ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found