Description
Please provide us with the following information:
This issue is for a: (mark with an x
)
- [X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
The issue was found for the following scenario:
Please add an 'x' for the scenario(s) where you found an issue
- Web app that signs in users
- with a work and school account in your organization: 1-WebApp-OIDC/1-1-MyOrg
- with any work and school account: /1-WebApp-OIDC/1-2-AnyOrg
- with any work or school account or Microsoft personal account: 1-WebApp-OIDC/1-3-AnyOrgOrPersonal
- with users in National or sovereign clouds 1-WebApp-OIDC/1-4-Sovereign
- with B2C users 1-WebApp-OIDC/1-5-B2C
- Web app that calls Microsoft Graph
- Calling graph with the Microsoft Graph SDK: 2-WebApp-graph-user/2-1-Call-MSGraph
- With specific token caches: 2-WebApp-graph-user/2-2-TokenCache
- Calling Microsoft Graph in national clouds: 2-WebApp-graph-user/2-4-Sovereign-Call-MSGraph
- Web app calling several APIs 3-WebApp-multi-APIs
- Web app calling your own Web API
- Web app restricting users
- by Roles: 5-WebApp-AuthZ/5-1-Roles
- by Groups: 5-WebApp-AuthZ/5-2-Groups
- Deployment to Azure
- Other (please describe)
Repro-ing the issue
Repro steps
Create facsimile apps but with more than one web client application that uses the same SQL user token cache table (i.e. more than one Azure registered client app ID.)
Run one client application and log on with a particular work account, then run the other client application and log on with that same account.
Expected behavior
Both apps should allow me to log on via that single signed on account.
Actual behavior
The second application to try logging on throws a encryption exception at
args.TokenCache.DeserializeMsalV3(tokenCacheBytes, shouldClearExistingCache: true);
MSALAppSqlTokenCacheProvider.cs, line ~184
Possible Solution
In ClaimPrincipalExtension.cs, add the application ID to the Msal Account ID to differentiate which application wrote to the UserTokenCache table.
public static string GetMsalAccountId(this ClaimsPrincipal claimsPrincipal)
{
string userObjectId = GetObjectId(claimsPrincipal);
string tenantId = GetTenantId(claimsPrincipal);
// Same as GetObjectID, but look for claimtype == "aud"
var applicationId = GetApplicationId(claimsPrincipal);
if (!string.IsNullOrWhiteSpace(userObjectId) && !string.IsNullOrWhiteSpace(tenantId))
{
return $"{userObjectId}.{applicationId}.{tenantId}";
}
return null;
}
Update:
My suggested solution is not very good in that the aud
claim isn't present during logging out. I'm working around this by adding the claim to the User during the OnRedirectToIdentityProviderForSignOut
event just before calling the RemoveAccount
method. I'm curious to see if the problem lies elsewhere first.
Additional context/ Error codes / Screenshots
Any log messages given by the failure
Add any other context about the problem here, such as logs.
(N/A)
OS and Version?
Window 10, VS 2019, .NET Core 2.2
Versions
ASP.NET Core 2.2
Attempting to troubleshooting yourself:
- did you go through the README.md in the folder where you found the issue?
- did you go through the documentation:
Mention any other details that might be useful
Thanks! We'll be in touch soon.