2016-04-26 161 views
0

我註冊了從Microsoft graph sample appOffice 365的API的微軟圖形驗證失敗

和標準登錄示例應用程序的工作,但我儘量做到simplier通過使用此代碼:

 var authContext = new AuthenticationContext(Settings.AzureADAuthority); 

     var token = authContext.AcquireToken(Settings.O365UnifiedAPIResource, new ClientCredential(Settings.ClientId, Settings.ClientSecret)).AccessToken; 

我得到以下錯誤:Application with identifier '[ClientId here]' was not found in the directory microsoft.com

Setting.O365UnifiedAPIResource = @"https://graph.microsoft.com/"; 
Settings.AzureADAuthority = @"https://login.microsoftonline.com/common"; 

有誰知道可能是什麼問題?

+0

查看您所在Settings.ClientId,你替換[這裏客戶端Id]與客戶端ID字符串時,您註冊的示例應用程序,你得到你的項目? – Jackie

+1

@Aleksa。我遇到了和以前一樣的問題。您可以將您的AzureADAuthority修改爲「https://login.microsoftonline.com/YourTenantName」。然後代碼工作。 –

+0

@NanYu謝謝:) – Aleksa

回答

2
Settings.AzureADAuthority = @"https://login.microsoftonline.com/{tenant_id or tenant_name}"; 

使用客戶端憑證(客戶端ID +客戶端密鑰)獲取令牌時。您應該明確指定承租人。

例如:

https://login.microsoftonline.com/ {tenant_id}

https://login.microsoftonline.com/ {your_domain.onmicrosoft.com}

順便說一句,因爲該註冊將是示例應用程序,它會只有擁有被授權的Mail.Send權限。要獲取應用令牌,您還需要授予Azure AD中的應用級別權限,因爲您正在獲取應用令牌而不是用戶令牌。

enter image description here