The way I am obtaining a token for my apps looks currently like this:
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(_clientId)
.WithClientSecret(_clientSecret)
.WithAuthority(new Uri(_authority))
.Build();
var result = await app.AcquireTokenForClient("MY SCOPES ARRAY").ExecuteAsync();
But everytime I call "AcquireTokenAsync" another token is returned.
This means that there is no token cache used, but each single request to my APIs will also receive another token.
This is not necessary.
How can I configure the "ClientCredentialsTokenAcquisitionClient" to make use of a token cache?
Reading the official docs from Microsoft tells me only about a user token cache.
So if I am acquiring a token silently in the name of a user I know how to cache my tokens. But how to do this with confidential clients?
I want to prevents thousands of unnecessary calls to the token endpoint of MS.
Have you included this call in your setup ? It tells the library to cache the token. You can implement it in many ways, here is one example.
services.AddMemoryCache();