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] GetAccountAsync returns null when account is in returned collection from GetAccountsAsync

See original GitHub issue

Which Version of MSAL are you using ? MSAL 4.17.1, MSAL 4.19.0

Platform xamarin android

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
    • Integrated Windows Auth
    • Username Password
    • Device code flow (browserless)
  • Web App
    • Authorization code
    • OBO
  • Web API
    • OBO

Other? - please describe;

Is this a new or existing app? The app is in production, I haven’t upgraded MSAL, but started seeing this issue. I am not able to say exactly after which version I stared seeing this issue

Repro

var account = await _msalClient
    .GetAccountAsync(identifier)
    .ConfigureAwait(false);

if (account == null)
{
    var accounts = await _msalClient.GetAccountsAsync();
    account = accounts.FirstOrDefault(a => a.HomeAccountId.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase));
}
return account;

Expected behavior The account for the given identifier should be returned from the GetAccountAsync(identifier) call

Actual behavior GetAccountAsync(identifier) returns null but the call to get all accounts and then select the first 1 with the given identifier does return an account. GetAccountsAsync() returns many duplicate accounts (45 accounts in my case but only has 5 distinct accounts)

This is using brokered authentication with Authenticator

Possible Solution

Additional context/ Logs / Screenshots Authenticator Incident ID: 3SNRN2DT

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pmaytakcommented, May 1, 2021

Verified that this works (with both content provider and account manager) on the latest main (4.30.1). GetAccountAsync finds the account correctly and GetAccountsAsync returns only unique accounts. There’s been a few refactorings to that code since 4.19. Closing; @bemartin please reopen if it’s still an issue.

1reaction
bgavrilMScommented, Oct 28, 2020

@trwalke - can you take a look at this as you are investigating other issues in Android area?

Read more comments on GitHub >

github_iconTop Results From Across the Web

PublicClientApplication - GetAccountsAsync() doesn't ...
I'm developing a little WPF-App that is supposed to query some data from the MS Graph API. I want to use SSO, so...
Read more >
ConfidentialClientApplication GetAccountsAsync returns ...
Returns all cached accounts details but sometimes it returns null. What might be the reason. I'm instantiating app variable everytime.
Read more >
ASP.NET Framework MSGraph empty GetAccountsAsync()
When you call GetAccountsAsync for the first time or if you the token cache is empty it can return empty accounts collection.
Read more >
OAuth 2.0: app.GetAccountsAsync returns null
GetAccountsAsync returns all the available accounts in the user token cache ... It's obvious it will return empty collection on first run.
Read more >
TokenAcquisition.cs
It uses the code to request an access token from the Microsoft Identity platform and caches the tokens and an entry about the...
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