简体   繁体   English

Azure MSAL:将令牌缓存与客户端凭据一起使用

[英]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.

相关问题 如何清除 MSAL SPA 中的缓存令牌? - How to Clear the cache token in MSAL SPA? 使用令牌 msal 连接到数据库 oracle - Connect to database oracle using token msal Azure Active Directory Oauth 2.0 客户端凭证流与 API 管理访问令牌问题 - Azure Active Directory Oauth 2.0 Client Credentials Flow with API Management Access Token issue az acr 登录导致错误:无法从 MSAL 缓存中找到令牌 - az acr login results in error: can’t find token from MSAL cache MSAL - 如何使用 Angular 13 兼容的 MSAL 库获取 ID 令牌 - MSAL - How to get ID token using Angular 13 compatible MSAL Library 将 com.microsoft.graph.requests.GraphServiceClient 与 azure 身份的客户端凭据提供程序一起使用时出现问题 - Issue while using com.microsoft.graph.requests.GraphServiceClient with Client credentials provider of azure identity 带有 Azure AD (MSAL) 的赛普拉斯 - Cypress with Azure AD (MSAL) 您能否通过 web 请求使用用户名和密码而不使用 client_id 获得 Azure 的访问令牌? - Can you get an access token for Azure with a username and password and without using a client_id via web request? Azure 应用程序配置、Key Vault 和客户端证书凭据 - Azure App Configuration, Key Vault and client certificate credentials 如何从应用程序客户端在 azure JS SDK 中生成 SAS 令牌,而不使用帐户密钥 - How to generate SAS token in azure JS SDK, from app client, without using account key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM