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] "offline_access" "openid" scope causes token cache misses

See original GitHub issue

Which 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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
henrik-mecommented, Jan 6, 2020

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.

1reaction
bgavrilMScommented, Jan 6, 2020

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 for offline_access, but that is more intrusive.

Read more comments on GitHub >

github_iconTop 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 >

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