Azure AD Graph API 400错误请求和401未授权错误

时间:2016-11-01 19:05:42

标签: asp.net vb.net azure-active-directory azure-ad-graph-api

我使用以下代码获得 400错误请求

Dim client As New WebClient()
client.Headers.Add("content-type", "application/x-www-form-urlencoded")
client.Headers.Add("Authorization", "Bearer **my-access-token-here**")
Dim groupsResponse As String = client.UploadString("https://graph.windows.net/myorganization/groups", "api-version=1.6")

我使用以下代码获得 401 Unauthorized

Dim client As New WebClient()
client.Headers.Add("content-type", "application/x-www-form-urlencoded")
client.Headers.Add("Authorization", "Bearer **my-access-token-here**")
Dim groupsResponse As String = client.DownloadString("https://graph.windows.net/myorganization/groups?api-version=1.6")

我从这个OAuth2端点获取了我的访问权限:

https://login.microsoftonline.com/**my-tentant-id-here**/oauth2/token

它所说的" myorganization"我也尝试用我的租户ID代替" myorganization"。结果相同。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

400 错误是因为您尝试将错误的数据格式(字符串)发布到错误的REST API端点。

如果您想申请论坛,可以参考下面的REST(参考here):

get: https://graph.windows.net/{tenant_id}/groups?api-version=1.6

对于 401 错误,您可能会显示详细错误消息,以便我们可以识别根本原因。您还可以解析来自here的令牌,以验证aud声明是否为https://graph.windows.net并且是否有足够的权限来调用群组REST,例如Group.Read.All,{{1} },Group.ReadWrite.AllDirectory.Read.All

相关问题