2017-03-16 134 views
1

我使用此代碼示例: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

+0

您是否嘗試過註銷並再次登錄以測試此場景? –

回答

1

我可以重現您的錯誤。根據this link,在使用AcquireTokenSilentAsync(使用NaiveSessionCache)時,似乎代碼示例不起作用,請嘗試將NaiveSessionCache.cs修改爲this

請讓我知道它是否有幫助。

+0

我有一個與此代碼示例相關的新問題,請參閱此處:http://stackoverflow.com/questions/42920678/how-can-i-get-refresh-token – Phoenix

相關問題