AzureAD / microsoft-authentication-library-for-java

Microsoft Authentication Library (MSAL) for Java http://aka.ms/aadv2
MIT License
285 stars 142 forks source link

Force a token refresh when claims are part of a silent request #794

Closed Avery-Dunn closed 1 month ago

Avery-Dunn commented 7 months ago

Currently MSAL Java will return a cached token even if the request has some non-empty claims. The request could be expecting an access token with different claims than the one that was cached, leading to a new claims challenge when the token is used.

To avoid this, the silent flow behavior should match the behavior in MSAL .NET, which is to force a refresh if there are claims in the request: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/main/src/client/Microsoft.Identity.Client/Internal/Requests/Silent/CacheSilentStrategy.cs#L47

crimsonvspurple commented 7 months ago

I was gonna request something like this too. Would love a way to skip the cache on demand.

Avery-Dunn commented 7 months ago

Hello @crimsonvspurple : This is for a specific case where an access token may have been invalidated so the cached one might have the wrong claims, and the acquireTokenSilently API can/should handle it. Is that the same scenario you're working with, or is there some other scenario where you'd want the silent flow to skip the cache?

Because when using any other acquireToken API that isn't acquireTokenSilently, you should already be able to skip the cache:

bgavrilMS commented 7 months ago

Marking this is a bug, as it is inconsistent with the other MSALs. Thanks for discovering this.

Related work item: https://github.com/AzureAD/microsoft-authentication-library-for-java/issues/757 (should be done together, as the other one has advanced test cases).

~Normally this would be a P1 as it blocks 2 important scenarios (claim injection and CAE), but there is a workaround with "force refresh" so marking as P2.~

Avery-Dunn commented 1 month ago

Fixed as part of https://github.com/AzureAD/microsoft-authentication-library-for-java/pull/811 and released in 1.17.0