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.

[Feature Request] Provide a way of clearing the in-memory token cache for a ConfidentialClientApplication

See original GitHub issue

Sometimes an application might be updated on Azure to have more permissions added to it, when this happens, if a token is already cached by my ConfidentialClientApplication, there is no way (that I know of) to remove a token that is already cached, to force a “refresh”. So all the subsequent requests to my resource will return 403 until the token expires from cache and a new one is obtained.

I tried using the GetAccountsAsync method documented here, but, even though it doesn’t explicitly say anything regarding this, it only handles user tokens.

There should be a way to force clearing the token cache. The way I see this getting implemented in my application is having a retry policy that tries to obtain a new token whenever a call to my resource returns 403, to make sure my token is refreshed.

I see a few ways this could be possible:

  • Getting something like the “AppAccounts” so I can manually remove them.
  • Clearing the cache explicitly
  • Having a way to force a bypass from cache when requesting a new token (AcquireTokenForClient).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bgavrilMScommented, Jul 14, 2022
2reactions
jmprieurcommented, Jul 13, 2022

Did you try the .WithForceRefresh(true) call on the builder retruned by app.AcquireTokenXXX() methods?\

app.AcquireTokenForClient(scopes)
 .WithForceRefresh(true)
 .ExecuteAsync();
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] In memory token cache in confidential ...
[Feature Request] In memory token cache in confidential client application is well partitioned for all flows, non longer serialized and can be shared ......
Read more >
Acquire and cache tokens with Microsoft Authentication ...
There are several ways to acquire a token by using the Microsoft Authentication Library (MSAL). Some require user interaction through a web ...
Read more >
msal.application.ConfidentialClientApplication class
Sets the token cache used by this ClientApplication instance. By default, an in-memory cache will be created and used. http_client. default value: None....
Read more >
MSAL Python 1.23.0 documentation
cache¶ (TokenCache) – Sets the token cache used by this ClientApplication instance. By default, an in-memory cache will be created and used.
Read more >
Getting request time out randomaly while getting access ...
Obtaining multiple tokens asynchronously does not seem to work. One Confidential Client Application for each token cache.
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