【发布时间】:2021-01-22 21:09:53
【问题描述】:
我正在尝试在我的企业中开发一个应用程序,我已关注this tutorial 以访问 AD 用户信息。含义:
- 我在https://apps.dev.microsoft.com/ 中创建了一个应用程序
- 我在 Application Permissions 中设置了
User.Read.All,在 Delegated Permissions 中设置了User.Read
完成此操作后,我能够成功登录(Azure AD OAuth2,https://graph.microsoft.com/ 作为资源,User.Read 作为范围)并从 https://graph.microsoft.com/v1.0/me 获得正确响应。
- 向管理员询问委派权限
这样,我的管理员可以在azure portal 中看到我的应用程序具有他自己同意的两个权限。
这是有效的,因为我要求一位同事登录并且我可以从 https://graph.microsoft.com/v1.0/me 得到正确的回复,即使他甚至没有被提示同意这一点(在管理员同意权限之前提示用户)
从
https://login.microsoftonline.com/common/oauth2/token请求令牌,以client_credentials作为response_type收到令牌!
-
向
https://graph.microsoft.com/v1.0/users发出 GET 请求并接收:{ "error": { "code": "Authorization_IdentityNotFound", "message": "The identity of the calling application could not be established.", "innerError": { "request-id": "b2d9ec62-0b65-44eb-9e0f-4aec52b45750", "date": "2017-03-22T19:19:48" } } }
此外,向https://graph.microsoft.com/v1.0/me 发出请求会返回:
{
"error": {
"code": "BadRequest",
"message": "Current authenticated context is not valid for this request",
"innerError": {
"request-id": "047e2ba9-a858-45fc-a0dd-124e1db503f3",
"date": "2017-03-22T19:39:25"
}
}
}
这让我相信微软知道这个令牌并且知道它没有冒充任何用户。
我一直在寻找有关 Azure AD 和 Microsoft Graph 身份验证的文档,但我只找到博客文章,而且所有文章似乎都已过时(尽管大多数功能都处于预览状态)。 如果你能指出我正确的方向,我会感谢你。
我还在 SO 上发现了 this 和 this 类似的问题,但它们都没有得到解答。
更新,this answer
谢谢你,丹, 我使用了我的组织域名,也可以获得令牌。
现在https://graph.microsoft.com/v1.0/users/ 的回复是:
{
"error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "3f190b47-73f5-4b29-96f9-54ed3dbc3137",
"date": "2017-03-23T11:07:15"
}
}
}
这没有任何意义,因为在 azure 门户中,我有 User.Read.All 作为应用程序权限(已经得到管理员的同意)。
我认为问题在于对令牌的请求,无论我发送scope,它都会成功返回,即使我编造了一个。
例如:
POST https://login.microsoftonline.com/<domain>/oauth2/token
client_id:*******
client_secret:*******
resource:https://graph.microsoft.com/
grant_type:client_credentials
scope:Foo.Bar
返回:
{
"token_type": "Bearer",
"expires_in": "3599",
"ext_expires_in": "0",
"expires_on": "1490271617",
"not_before": "1490267717",
"resource": "https://graph.microsoft.com/",
"access_token": *****
}
【问题讨论】:
标签: azure-active-directory microsoft-graph-api azure-ad-graph-api