【发布时间】:2021-04-29 09:27:24
【问题描述】:
我正在(成功地)使用带有 MSAL 的客户端凭据流来验证这样的应用程序:
private static async Task<AuthenticationResult> getAuthResultNonInteractively()
{
string[] scopes = {"api://xxx/.default"};
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.CreateWithApplicationOptions(
new ConfidentialClientApplicationOptions
{
TenantId = "xxx",
ClientId = "xxx",
RedirectUri = "http://localhost",
ClientSecret = "xxx"
})
.Build();
// Desired behaviour: acquires token online only if token does not
// exist in cache or is expired
AuthenticationResult authResult = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
return authResult;
}
对AcquireTokenForClient的调用是否首先尝试在令牌缓存中查找令牌,并且仅当缓存中不存在令牌或令牌已过期时才在线获取它?还是它总是在线获取令牌?如果后者为真,我需要进行哪些更改才能获得所需的行为?
【问题讨论】: