[英]Azure MSAL: Using the Token cache with client credentials
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.但是每次我调用“AcquireTokenAsync”时都会返回另一个令牌。
This means that there is no token cache used, but each single request to my APIs will also receive another token.这意味着没有使用令牌缓存,但对我的 API 的每个请求也会收到另一个令牌。
This is not necessary.这是没有必要的。
How can I configure the "ClientCredentialsTokenAcquisitionClient" to make use of a token cache?如何配置“ClientCredentialsTokenAcquisitionClient”以使用令牌缓存?
Reading the official docs from Microsoft tells me only about a user token cache.阅读 Microsoft 的官方文档只告诉我有关用户令牌缓存的信息。
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.我想防止对 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.