简体   繁体   English

通过Rest Call查询Windows Azure Active Directory图表Api

[英]Querying the Windows Azure Active Directory Graph Api by Rest Call

According to this: http://msdn.microsoft.com/en-us/library/windowsazure/dn424880.aspx and this http://msdn.microsoft.com/en-us/library/windowsazure/hh974467.aspx 根据这个: http//msdn.microsoft.com/en-us/library/windowsazure/dn424880.aspx和这个http://msdn.microsoft.com/en-us/library/windowsazure/hh974467.aspx

I should be able to do a get request 我应该可以做一个get请求

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

and I am using Fiddler just get started. 我正在使用Fiddler刚入门。 Setting this in the composer: User-Agent: Fiddler Host: graph.windows.net Authorization: Bearer eyJ0eXA .... (My Token, used some c# from WAAL to get the token). 在作曲家中设置:User-Agent:Fiddler Host:graph.windows.net授权:Bearer eyJ0eXA ....(我的令牌,使用来自WAAL的一些c#来获取令牌)。

This is what is returned 这是返回的内容

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."}}}

The token is accepted when I do some stuff in my application so I dont belive its malformed. 当我在我的应用程序中执行某些操作时,令牌被接受,所以我不相信它的格式错误。

I kept running into this problem. 我一直遇到这个问题。 I was using the following code to get a bearer token for my native app: 我使用以下代码为我的原生应用程序获取持票人令牌:

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

Using that token worked fine for authorizing actions within my own app, but I'd get the same error as the OP when trying to use the same token as authorization for the Graph API. 使用该令牌可以很好地在我自己的应用程序中授权操作,但是当我尝试使用相同的令牌作为Graph API的授权时,我会得到与OP相同的错误。

What I had to do was get a new token specifically for the Graph API - I used the same code as above but I used "https://graph.windows.net" instead of "MYAPP_ID" . 我必须做的是专门为Graph API获取一个新令牌 - 我使用了与上面相同的代码,但我使用了"https://graph.windows.net"而不是"MYAPP_ID" So, to be clear, the following code gave me the correct OAuth token for the Graph API: 因此,为了清楚起见,以下代码为Graph 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;
        }

Just make sure that your application registered in Azure has the necessary permissions to access your Azure domain's directory. 只需确保在Azure中注册的应用程序具有访问Azure域目录所需的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Microsoft Graph API(非Azure AD API)查询Azure Active Directory中的自定义属性 - Querying Custom attributes in Azure Active Directory using Microsoft Graph API (NOT Azure AD API) 从未在 Azure Active Directory Graph API Delta 调用中收到“@odata.nextLink” - Never receiving "@odata.nextLink" in Azure Active Directory Graph API Delta call 还原已删除的目录Azure Active Driectory对象 - Azure Graph API - Restore Deleted Directory Azure Active Driectory Object - Azure Graph API 如何通过Azure Active Directory授权使用Azure REST API应用 - How to consume Azure REST API App with Azure Active Directory authorization On 使用图API API在Azure Active Directory中创建应用程序失败 - Create application in Azure Active Directory using graph API fails 如何使用图谱API在Azure活动目录中创建自定义角色? - How to create custom role in azure active directory using graph api? 使用图形api在Azure Active目录组中搜索用户 - Search for user in Azure Active directory group using graph api 使用图形api以编程方式在azure活动目录中注册应用程序 - Programmatically register app in azure active directory using graph api 如何使用图形API在Azure活动目录中添加外部用户 - How to add the external user in azure active directory using graph api 用于更改 Azure Active Directory 用户个人资料图片的 REST API - REST API to change Azure Active Directory user profile picture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM