0
我可以緩存爲租戶生成的令牌,同時創建GraphServiceClient並重新使用它,如果有的話令牌有效多久?是什麼導致它到期? 我的代碼使用IAuthenticationProvider並實現用於AuthenticationContext的緩存授權令牌
public async Task AuthenticateRequestAsync(HttpRequestMessage request)
{
AuthenticationContext authContext = new AuthenticationContext(url.ToString());
ClientCredential creds = new ClientCredential(clientId, clientSecret);
AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com", creds);
request.Headers.Add("Authorization", "Bearer " + token);
}