[Bug] "offline_access" "openid" scope causes token cache misses
See original GitHub issueWhich Version of MSAL are you using ? Microsoft Identity 4.7.1
Platform Xamarin.Forms on iOS and Android
What authentication flow has the issue?
- Desktop / Mobile
- Interactive
- Integrated Windows Auth
- Username Password
- Device code flow (browserless)
Other? - AcquireTokenSilent
Is this a new or existing app? This is a new app.
Repro Login to AD B2C with email credentials. Create a loop that calls AcquireTokensSilent repeatedly. Notice that a new access token is returned every time, even though it is not close to expiring.
public async Task<UserContext> AcquireAccessToken()
{
IEnumerable<IAccount> accounts = await PCA.GetAccountsAsync();
AuthenticationResult authResult = await PCA.AcquireTokenSilent(_configuration.Scopes, GetAccountByPolicy(accounts, _configuration.PolicySignUpIn))
.WithB2CAuthority(_configuration.AuthoritySignInUp)
.ExecuteAsync();
var newContext = UpdateUserInfo(authResult);
AccessToken = newContext.AccessToken;
Debug.WriteLine($"Access token is {newContext.AccessToken}");
return newContext;
}
Expected behavior I expected that the access token would be pulled from cache and not refreshed.
Actual behavior Access token is refreshed every time, even when it doesn’t need to be.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
AcquireTokenSilently with empty scope causes AT cache ...
Run AcquireTokenByXXX to acquire token for an empty scope (scope= ""); Use same client app to acquire token silently with same parameters.
Read more >Scope "offline_access" isn't being returned in the token ...
The offline_access scope is used to request for Refresh Token and is never returned as a scope because it cannot be a part...
Read more >c# - IDX21323 OpenIdConnectProtocolValidationContext. ...
In my case the cause was clicking the browser's back button after login. This causes the cached NONCE to be used which then...
Read more >Managing tokens for Zero Trust
MSAL automatically caches tokens but the tokens have lifetimes. Use tokens through the full length of their lifetimes and appropriately cache ...
Read more >Duende BFF unauthorized client error when calling Identity ...
Found the issue. I was registering the named http client as AddClientAccessTokenHttpClient services.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As per internal discussion seems like we have to improve the cache lookup filtering out OIDC scopes? I don’t think we should ask people to do anything we should be able to filter correctly and do appropriate cache lookup.
Yeah, I think this is the problem. MSAL requests offline_access but ESTS when it responds does not add
offline_access
to the response (mind you, it does give you a refresh token). This causes a problem in the token cache.@jmprieur @henrik-me, @shoatman - I think we can make a small fix for this in MSAL, i.e. if the developer asks for
offline_access
, do not use this scope to look in the cache. Alternatively, we can ban people from explicitly asking foroffline_access
, but that is more intrusive.