2014-01-14 77 views
8

根據此: http://msdn.microsoft.com/en-us/library/windowsazure/dn424880.aspxhttp://msdn.microsoft.com/en-us/library/windowsazure/hh974467.aspx通過REST調用查詢在Windows Azure Active Directory的圖形API

我應該可以做一個GET請求

https://graph.windows.net/<my-object-guid>/tenantDetails?api-version=0.9 

,我使用招剛開始。在作曲家中設置: 用戶代理:提琴手 主持人:graph.windows.net 授權:持票人eyJ0eXA ....(我的令牌,使用一些來自WAAL的c#來獲取令牌)。

這就是返回

HTTP/1.1 401 Unauthorized 
Cache-Control: private 
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8 
Server: Microsoft-IIS/8.0 
WWW-Authenticate: Bearer realm="<my-object-guid>", error="invalid_token", error_description="Access Token missing or malformed.", authorization_uri="https://login.windows.net/<my-object-guid>/oauth2/authorize", client_id="00000002-0000-0000-c000-000000000000" 
ocp-aad-diagnostics-server-name: 11iIdMb+aPxfKyeakCML7Tenz8Kyy+G8VG19OZB/CJU= 
request-id: 99d802a3-0e55-4018-b94d-a8c00ec8f171 
client-request-id: 7ed93efd-86c5-4900-ac1f-747a51fe1d8a 
x-ms-dirapi-data-contract-version: 0.9 
X-Content-Type-Options: nosniff 
DataServiceVersion: 3.0; 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
X-Powered-By: ARR/3.0 
X-Powered-By: ASP.NET 
Date: Tue, 14 Jan 2014 00:13:27 GMT 
Content-Length: 129 

{"odata.error":{"code":"Authentication_MissingOrMalformed","message":{"lang":"en","value":"Access Token missing or malformed."}}} 

當我做一些東西在我的應用程序,所以我不相信的其畸形的令牌被接受。

+2

你有沒有得到這個解決?我遇到了同樣的錯誤 – rwisch45

+0

我不這麼認爲,在我遇到問題後,再也沒有嘗試過。 –

回答

16

我一直在遇到這個問題。我用下面的代碼爲我的本機應用程序的承載令牌:

 var authContext = new AuthenticationContext("AUTHORITY"); 
     string token; 
     try 
     { 
      var authresult = authContext.AcquireToken("MYAPP_ID","MYAPP_CLIENTID","MYAPP_REDIRECTURI"); 
      token = authresult.AccessToken; 
     } 

使用該令牌工作的罰款爲自己的應用程序內授權的行動,而是努力時,我會得到相同的錯誤的OP使用與Graph API的授權相同的標記。

我所要做的就是獲得專門用於Graph API的新令牌 - 我使用了與上面相同的代碼,但我使用"https://graph.windows.net"而不是"MYAPP_ID"。因此,要明確,下面的代碼給了我圖形API正確的OAuth令牌:

 var authContext = new AuthenticationContext("AUTHORITY"); 
     string token; 
     try 
     { 
      var authresult = authContext.AcquireToken("https://graph.windows.net","MYAPP_CLIENTID","MYAPP_REDIRECTURI"); 
      token = authresult.AccessToken; 
     } 

只要確保你在Azure中註冊的應用具有必要的權限來訪問您的Azure中域的目錄。

+1

我在使用Fiddler來解決同樣的問題。我試過你的解決方案,它工作!我正在使用Fiddler捕捉我的應用程序流量。我編輯了POST令牌請求中的'resource'值爲「https://graph.windows.net」我獲得授權我執行來自fiddler的請求的訪問代碼到https://graph.windows.net/x/羣體?API版本= 1.5。非常感謝!! –

+0

爲什麼我需要獲得另一個access_token才能獲取用戶詳細信息,我已經擁有此用戶的訪問令牌。 – Dabbas

+0

另請注意,如果您剛剛爲您的AD應用程序授予讀取和訪問目錄的權限,則可以需要等幾個小時才能生效。同時,您可能會收到'沒有足夠的權限來完成操作'。 –

相關問題