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] [L] TokenCacheNotificationArgs should expose the token expiry so that cache can optimize eviction (client_credentials only)

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jmprieurcommented, Jun 11, 2021

@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) ?

0reactions
trwalkecommented, Jul 8, 2021

released in 4.34.0

Read more comments on GitHub >

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

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