I have a problem to figure out how implement cache with AcquireTokenOnBehalfOf. Every time when I call code below for the same user I get different token, so I suppose that there is no inner cache mechanism or something like that.
var app = ConfidentialClientApplicationBuilder.Create(ClientId)
.WithClientSecret(ClientSecret)
.WithAuthority(authority)
.Build();
var result = await app.AcquireTokenOnBehalfOf(new[] { "https://graph.microsoft.com/.default" }, userAssertion)
.ExecuteAsync()
.ConfigureAwait(false);
I tried to add app.AddInMemoryTokenCache();
from Microsoft.Identity.Web and it works but then one request can last even 21 seconds and this is not an option.
Is anyone who faced problem like that?
Edit: I found some solution. I added to ConfidentialClientApplicationBuilder two lines and now it take tokens from cache:
.WithLegacyCacheCompatibility(false)
.WithCacheOptions(CacheOptions.EnableSharedCacheOptions)