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.

[Bug] Broker AcquireTokenInteractive() doesn't cache when it fallbacks

See original GitHub issue

Logs and network traces {MSAL.Xamarin.Android.4.54.1.0.MsalUiRequiredException: ErrorCode: failed_to_acquire_token_silently_from_broker Microsoft.Identity.Client.MsalUiRequiredException: Broker could not satisfy the silent request. at Microsoft.Identity.Client.Internal.Requests.Silent.SilentRequest.ExecuteAsync (System.Threading.CancellationToken cancellationToken) [0x002d7] in <f5e0daf1cb4c43c889fca0f3b0814e85>:0 at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync (System.Threading.CancellationToken cancellationToken) [0x001c5] in <f5e0daf1cb4c43c889fca0f3b0814e85>:0 at Microsoft.Identity.Client.ApiConfig.Executors.ClientApplicationBaseExecutor.ExecuteAsync (Microsoft.Identity.Client.ApiConfig.Parameters.AcquireTokenCommonParameters commonParameters, Microsoft.Identity.Client.ApiConfig.Parameters.AcquireTokenSilentParameters silentParameters, System.Threading.CancellationToken cancellationToken) [0x00144] in <f5e0daf1cb4c43c889fca0f3b0814e85>:0 at WiFiMessenger.Services.Communication.OIDCToken.StartRefreshingTokensAsync () [0x0010a] in F:\Code\Work\Wi-Fi Messenger\Client\Client\WiFiMessenger\Services\Communication\OIDCToken.cs:189 StatusCode: 0 ResponseBody:
Headers: }

Which version of MSAL.NET are you using? 4.54.1

Platform Xamarin.Android

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive (broker)
    • Interactive (embedded or system browser)
    • Integrated Windows Authentication
    • Username / Password
    • Device code (browserless)
  • Web app
    • Authorization code
    • On-Behalf-Of
  • Daemon app
    • Client credentials (service-to-service calls)

Is this a new or existing app? new

Actual behavior When I get a token using AcquireTokenInteractive with my PublicClientApplication built WithBroker(), and the device does not have a broker installed, so it should fall back to webview. When I get that token I try to refresh it periodically using AcquireTokenSilent and the account hint that was in the token. The acquire fails and gives above exception. When I try the same with the WithBroker() commented out, so not using broker flow. Everything works as expected.

Expected behavior use the cached token that was gathered seconds ago using the interactive login

Possible solution If i call

.WithBroker( PublicClientApplicationBuilder.Create( applicationId ).IsBrokerAvailable());

I understand this is deprecated but it works for me in the meantime until there is an official fix

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bgavrilMScommented, Jul 21, 2023

Ack, we will aim to get this fixed.

Please use the IsBrokerAvailable, it should work fine, but we just didn’t want app developers to use it, as MSAL should fallback to browser on its own.

2reactions
LennoxP90commented, Jul 12, 2023

so your repro would be as follows:

WithBroker = true

  1. AcquireTokenInteractive but broker is not installed, so a webview is used (internally this should make MSAL cache a token)
  2. AcquireTokenSilent fails with the above error message
  3. Later, the broker gets installed
  4. AcquireTokenSilent starts working
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] AcquireTokenSilent / GetAccounts / RemoveAccounts ...
AcquireTokenSilent should first try to get a token from local cache and, if none is available, from the broker. Note: the local cache...
Read more >
WAM · AzureAD/microsoft-authentication-library- ...
This component acts as an authentication broker and users of your app ... fallback experience on older Windows, Mac and Linux etc. which...
Read more >
Gathering a cached token via AqcuireTokenSilent fails
I have a condition set to where if there's a cached token, it will use that or else it will either look for...
Read more >
Migrate public client applications to MSAL.NET
Learn how to migrate a public client application from Azure Active Directory Authentication Library for .NET to Microsoft Authentication ...
Read more >
Acquire and cache tokens with Microsoft Authentication ...
Application source code should first try to get a token silently from the cache. If the method call returns a "UI required" error...
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