2016-07-28 126 views

回答

1

您可以使用客戶端證書來請求令牌而不是OAuth 2.0代碼授權流程

這是給你參考的要求:

POST https://login.microsoftonline.com/<tenantId>/oauth2/token HTTP/1.1 
Content-Type: application/x-www-form-urlencoded 

grant_type=client_credentials 
&client_id=<clientId> 
&client_secret=<clientSecret> 
&resource=https://outlook.office.com 

這裏是使用Microsoft.IdentityModel.Clients.ActiveDirectory要求興田令牌樣本:

public static async Task<string> GetTokenAsync(string resource, string clientId, string secrect) 
    { 
     string authority = "https://login.microsoftonline.com/{yourTenantName}"; 
     AuthenticationContext authContext = new AuthenticationContext(authority); 

     ClientCredential clientCredential = new ClientCredential(clientId, secrect); 
     AuthenticationResult authResult=await authContext.AcquireTokenAsync(resource, clientCredential); 
     return authResult.AccessToken; 
    } 

更多細節有關Office 365 REST,請參閱here

+0

如果我理解正確,我需要支付才能獲得tenantId? –

+0

是的。您可以登錄經典的Azure門戶,您可以從瀏覽器的URL中獲取tenantId,例如https://manage.windowsazure.com/rekenoutlook.onmicrosoft.com#Workspaces/ActiveDirectoryExtension/Directory/{tenantId}/directoryQuickStart。 –

相關問題