据此: http://msdn.microsoft.com/en-us/library/windowsazure/dn424880.aspx 和这个 http://msdn.microsoft.com/en-us/library/windowsazure/hh974467.aspx
我应该能够执行获取请求
https://graph.windows.net/<my-object-guid>/tenantDetails?api-version=0.9
我刚刚开始使用Fiddler。在 Composer 中设置: 用户代理:Fiddler 主机:graph.windows.net 授权:Bearer eyJ0eXA ....(我的 token ,使用 WAAL 中的一些 c# 来获取 token )。
这就是返回的内容
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."}}}
当我在应用程序中执行某些操作时, token 会被接受,因此我不相信它的格式错误。
最佳答案
我一直遇到这个问题。我使用以下代码为我的 native 应用程序获取不记名 token :
var authContext = new AuthenticationContext("AUTHORITY");
string token;
try
{
var authresult = authContext.AcquireToken("MYAPP_ID","MYAPP_CLIENTID","MYAPP_REDIRECTURI");
token = authresult.AccessToken;
}
使用该 token 可以很好地在我自己的应用程序中授权操作,但是当尝试使用相同的 token 作为 Graph API 的授权时,我会得到与 OP 相同的错误。
我必须做的是专门为 Graph API 获取一个新 token - 我使用了与上面相同的代码,但我使用了 "https://graph.windows.net"
而不是 “MYAPP_ID”
。因此,需要明确的是,以下代码为我提供了 Graph API 的正确 OAuth token :
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 域目录所需的权限即可。
关于c# - 通过 Rest Call 查询 Windows Azure Active Directory Graph Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21103927/