Questions about acquireTokenByClientCredential caching

Dionisio, Ryne 0 Reputation points
2025-08-04T15:32:58.91+00:00

We are using acquireTokenByClientCredential to get an app-to-app token. We tried using the same user multiple times and it seemed to cache since I didn't see any extra calls going out to MS. But I did have a couple questions:

  1. What is the TTL of this cached token?
  2. Is there any documentation that explains how the cache for this works? From documentation found here I found this section:

"Since this is a “client credentials flow”, this uses the application token cache. This method takes care of verifying the application token cache before sending a request to the security token service (STS)."

But that's as much as I could find on it

Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sreetheja Adusumilli 325 Reputation points Microsoft External Staff Moderator
    2025-08-21T17:02:22.9566667+00:00

    Hello Dionisio, Ryne,

    Thanks for posting your question in Microsoft Q&A!

    When you use acquireTokenByClientCredential to get a token for your app, the Microsoft Authentication Library (MSAL) saves that token in a cache. This is why when you use the same app multiple times, you don’t see extra calls to Microsoft every time — because MSAL reuses the cached token.

    How long does the token last?

    The token usually lasts about 60 minutes. MSAL keeps it stored and hands it back as long as it hasn’t expired. When the token is about to expire or has expired, MSAL automatically fetches a new one.

    How does the caching work?

    Before contacting Microsoft, MSAL checks if there’s still a valid token in its cache. If yes, it uses that token instead of asking Microsoft again. If there isn’t, or the token is expired, it will request a new token and update the cache.

    Microsoft has this info in their documentation here:

    About application token caching: https://learn.microsoft.com/azure/active-directory/develop/msal-client-application#application-token-cache

    About token renewal: https://learn.microsoft.com/azure/active-directory/develop/msal-client-application#token-caching-and-renewal

    Best Practices:

    • Let MSAL take care of caching and refreshing tokens — no need to do this yourself.
    • If a token expires, just handle the error and MSAL will get a new one automatically.
    • If you want tokens to last longer or shorter, you can set token lifetimes in Azure AD, but it’s usually best to use the default settings.

    Kindly let us know if the above helps or you need further assistance on this issue.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.