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] AADSTS50020 error if signing out then into another tenant without restarting the app

See original GitHub issue

Which Version of MSAL are you using ? MSAL 4.3.1

Platform all

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive

Description

In UWP apps (possibly also in non-UWP), if you execute the following sequence, an AADSTS50020 is issued:

  1. AcquireTokenInteractive() [user logs in successfully to CompanyA.com]
  2. AcquireTokenSilent() [this is required for the bug to appear]
  3. Log out (see code below)
  4. AcquireTokenInteractive() [user tries to login into CompanyB.com]

The user should be able to log into CompanyB, however we get this error:

AADSTS50020: User account ‘[someemail]’ from identity provider ‘https://sts.windows.net/[some_guid]/’ does not exist in tenant ‘[some name]’ and cannot access the application ‘[some_guid]’(AppName) in that tenant. The account needs to be added as an external user in the tenant first. Sign out and sign in again with a different Azure Active Directory user account.

Logout looks like this:

var accounts = await _graphApp.GetAccountsAsync();
while (accounts.Any())
{
	await _graphApp.RemoveAsync(accounts.FirstOrDefault());
	accounts = await _graphApp.GetAccountsAsync();
}

Additional Information

  1. If you restart the app between steps 3 and 4, things work as expected (user can log into CompanyB).
  2. Adding .WithAuthority(AadAuthorityAudience.AzureAdMultipleOrgs) to the app builder does not resolve the problem.

I have provided a sample app to demonstrate this problem. You must supply your own AppId.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
adamedxcommented, Oct 6, 2019

Yes, I updated shortly after it was released and everything works now 😃. I was able to incorporate it into a release (was originally planning on just relnoting the bug). Thanks very much for the quick turnaround on diagnosis, fix, and release.

2reactions
adamedxcommented, Sep 6, 2019

FYI, I hit this same problem, looking forward to a release with the fix and will share results once I get to try it out. Glad this issue was filed as I had been spending time trying to debug – I assumed it was my fault as I was in the process of migrating from the older MSAL with explicit caches to the new builder model with implicit cache.

Read more comments on GitHub >

github_iconTop Results From Across the Web

User account from identity provider does not exist in tenant ...
When a guest user tries to access an application or resource in the resource tenant, the sign-in fails, and the following error message...
Read more >
Error AADSTS50020 when signing into OneDrive
You can't sign in to the OneDrive sync app if you see error AADSTS50020 because of cached identities from the previous tenant.
Read more >
Multi-tenant app in Azure AD (Active Directory) fails with ...
The account needs to be added as an external user in the tenant first. Sign out and sign in again with a different...
Read more >
Microsoft Graph App sign in with different tenant not possible
The account needs to be added as an external user in the tenant first. Sign out and sign in again with a different...
Read more >
whiteboard.microsoft.com is giving an error when loading ...
this is the error I get on whiteboard and I also get another as well Something ... I have tried logging in and...
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