我正在使用仅限应用程序的权限查询 Microsoft Graph,因为我正在对目录中的所有用户执行操作。当我查询 onPremisesSamAccountName
时使用我的 token ,我没有任何问题。但是,当我尝试检索用户的照片(使用相同的 token )时,我得到以下信息:
StatusCode: 400 Bad Request
Error Code: AuthenticationError
Error Message: Error authenticating with resource
我在租户中分配了以下仅限应用程序的权限:
- User.Read.All(申请,管理员同意)
- Directory.Read.All(申请,管理员同意)
详细信息:
- URI:
https://graph.microsoft.com/v1.0/users/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="305d494543554270545f5d51595e1e535f5d" rel="noreferrer noopener nofollow">[email protected]</a>/photo/$value
- 范围:
https://graph.microsoft.com/.default
- 内容类型:
application/json
- 授权 header :
"bearer _my token string_"
这是我的请求(在 ColdFusion 中):
<cfhttp method="get" charset="utf-8" url="https://graph.microsoft.com/v1.0/users/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85e8fcf0f6e0f7c5e1eae8e4ecebabe6eae8" rel="noreferrer noopener nofollow">[email protected]</a>/photo/$value" result="resp">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="header" name="Authorization" value="bearer Oxfd989309sdf...">
</cfhttp>
我得到的回复就是我上面显示的内容。当我通过http://jwt.calebb.net/运行我的 token 时,我没有看到任何范围设置。
我尝试通过 Graph Explorer 运行它。我以我自己的身份登录,然后运行 URI https://graph.microsoft.com/v1.0/me/photo
,我收到的回复是:
{
"error": {
"code": "ErrorItemNotFound",
"message": "The photo wasn't found.",
"innerError": {
"request-id": "ebae50f8-b636-4e61-9d92-eab4b48ef0c2",
"date": "2019-08-08T19:13:50"
}
}
}
我希望如此,因为我没有照片。
当我使用 URI https://graph.microsoft.com/v1.0/users/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f5988c80869087b5988c919a98949c9bdb969a98" rel="noreferrer noopener nofollow">[email protected]</a>/photo/$value
时,我得到以下响应:
{
"error": {
"code": "ResourceNotFound",
"message": "Resource could not be discovered.",
"innerError": {
"request-id": "40246947-57d6-4016-a55a-c1ad5f0736e4",
"date": "2019-08-08T19:16:37"
}
}
}
我按照 the documentation 设计了我的请求其中显示了示例 GET
GET /users/{id | userPrincipalName}/photo/$value
我是否错过了一个步骤,或者遗漏了一个范围?
最佳答案
When I run my token through http://jwt.calebb.net/, I don't see any scopes set.
当您使用客户端凭证流程获取 token 时,您将获得角色下的权限。
I tried running this through Graph Explorer. I signed in as myself, then I ran the URI https://graph.microsoft.com/v1.0/me/photo, the response I received was:404
就像 @Marc LaFleur 在评论中所说,确保用户配置了 Exchange Online 邮箱,并上传了个人资料图片。
关于azure - 在 Graph 中检索照片时从 Microsoft 获取 "AuthenticationError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57419444/