Open edahlberg opened 3 months ago
TokenAcquisition always requests openid scope. What are you trying to achieve?
@bgavrilMS
This issue is split from https://github.com/AzureAD/microsoft-identity-web/issues/13 where people were using the "openid" scope as a workaround for that issue not being fixed. This is done in one of the official examples as well:
In that case, if any other api scope is ever requested alongside "openid", it messes up the cache. So if you were to add a downstream API call to that example project, it would have the same issue.
I didn't report this because I'm having an issue per se, but because it's wrong behavior from the cache and you asked me to do so: https://github.com/AzureAD/microsoft-identity-web/issues/13#issuecomment-2307144273
@bgavrilMS what would you advise? change in MSAL?
The error is almost always indicative of a bug in MSAL. However, I do not understand if this is OBO scenario or auth_code.
Microsoft.Identity.Web Library
Microsoft.Identity.Web.TokenAcquisition
Microsoft.Identity.Web version
3.1.0
Web app
Sign-in users and call web APIs
Web API
Protected web APIs call downstream web APIs
Token cache serialization
In-memory caches
Description
When requesting tokens for any of the scopes "openid", "profile" or "offline_access", it's possible to receive
Microsoft.Identity.Client.MsalClientException: The cache contains multiple tokens satisfying the requirements. Try to clear token cache.
This happens because when getting tokens from cache, these three scopes are explicitly ignored because they're "required" scopes. Code can be seen in TokenAcquisition.cs. ->
scopes.Except(_scopesRequestedByMsal)
. This means that a token with any scope will pass the requirements.Reproduction steps
With a configured application that can call downstream scopes, add a controller with the included code snippet below
Replace the custom api scope with a real downstream api/scope the application can access.
When called, the "var c" line will always throw
Microsoft.Identity.Client.MsalClientException: The cache contains multiple tokens satisfying the requirements. Try to clear token cache.
Error message
Microsoft.Identity.Client.MsalClientException: 'The cache contains multiple tokens satisfying the requirements. Try to clear token cache. '
Id Web logs
No response
Relevant code snippets
Include this in your controller with the middle api replaced.
Regression
No response
Expected behavior
Either the cache should return the right token, or requesting these "required" scopes should be disallowed.