[Feature Request] [L] TokenCacheNotificationArgs should expose the token expiry so that cache can optimize eviction (client_credentials only)
See original GitHub issueIs your feature request related to a problem? Please describe. In token cache serializers for confidential client applications:
- for user flows, a RT is present in the cache and expiration cannot be determined, because tokens can be refreshed indefinitely.
- for AcquireTokenForClient however, there is no RT and the expiration of the cache can be computed as the max over the expiration of each access token in cache.
Describe the solution you’d like
In TokenCacheNotificationArgs
add a new property of type SuggestedCacheExpiry
, and of the same type as the expiry in the token cache times (I suppose this is DateTimeOffset, but this needs to be checked).
This property will be computed by items.Max(item => item.ExpiresOnUnixTimestamp), and then convert that to a UtcDateTime.
class TokenCacheNotificationArgs
{
// Other members
/// <Summary>
/// Suggested value of the expiry, to help determining the cache eviction time.
// This value is <b>only</b> set on the <code>OnAfterAcces</code> delegate, on a cache write
/// operation (that is when <code>args.HasStateChanged<code> is <code>true</code>) and when the cache write
/// is triggered from the <code>AcquireTokenForClient<code> method. In all other cases it's <code>null<code>, as there is a refresh token, and therefore the
/// access tokens are refreshable.
/// </Summary>
UtcDateTime? SuggestedCacheExpiry {get; private set;}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Token cache serialization (MSAL.NET) - Microsoft Entra
If you want to use an in-memory token cache and control its size and eviction policies, use the Microsoft. Identity. Web in-memory cache...
Read more >Acquire and cache tokens with Microsoft Authentication ...
Application source code should first try to get a token silently from the cache. If the method call returns a "UI required" error...
Read more >Azure MSAL: Using the Token cache with client credentials
So if I am acquiring a token silently in the name of a user I know how to cache my tokens. But how...
Read more >Caching tokens - Amazon Cognito
You can cache the access tokens so that your app only requests a new access token if a cached token is expired. Otherwise,...
Read more >Vault Proxy Caching
Responses containing new tokens will be cached by the proxy only if the parent token is already being managed by the proxy or...
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
@bgavrilMS : yes it should be nullable, but I don’t think we have nullable in MSAL.NET? Yes, in the InAfterAccess, and probably only when (args.HasStateChanged) ?
released in 4.34.0