我使用此代碼示例:https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web,我知道這個代碼示例是使用客戶端庫,但如果我想perfrom查詢(使用httpclient)直接使用API調用,我使用下面的代碼來獲取訪問令牌緩存:無法默認獲取令牌,因爲在緩存中找不到令牌。調用方法AcquireToken
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID));
ClientCredential credential = new ClientCredential(clientId, appKey);
var result = await authContext.AcquireTokenSilentAsync(resource, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
但我發現總是拋出錯誤:由於在緩存中找不到令牌,無法默認獲取令牌。調用方法AcquireToken
您是否嘗試過註銷並再次登錄以測試此場景? –