azure - 在 Graph 中检索照片时从 Microsoft 获取“AuthenticationError”
问题描述
我正在使用仅限应用程序权限查询 Microsoft Graph,因为我正在对目录中的所有用户执行操作。当我onPremisesSamAccountName
用我的令牌查询时,我没有问题。但是,当我尝试为用户检索照片时(使用相同的令牌),我得到以下信息:
StatusCode: 400 Bad Request
Error Code: AuthenticationError
Error Message: Error authenticating with resource
我在租户中分配了以下仅限应用的权限:
- User.Read.All(应用程序,管理员同意)
- Directory.Read.All(应用程序,管理员同意)
细节:
- 网址:
https://graph.microsoft.com/v1.0/users/myuser@domain.com/photo/$value
- 范围:
https://graph.microsoft.com/.default
- 内容类型:
application/json
- 授权标头:
"bearer _my token string_"
这是我的要求(在 ColdFusion 中):
<cfhttp method="get" charset="utf-8" url="https://graph.microsoft.com/v1.0/users/myuser@domain.com/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/运行我的令牌时,我没有看到任何范围设置。
我尝试通过 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"
}
}
}
我会期待,因为我没有照片。
当我使用 URIhttps://graph.microsoft.com/v1.0/users/myuser@mydomain.com/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"
}
}
}
我在显示示例 GET的文档之后设计了我的请求
GET /users/{id | userPrincipalName}/photo/$value
我错过了一步,还是遗漏了一个范围?
解决方案
Graph v1.0 仅支持从 Exchange 邮箱检索照片。从文档中:
注意 1.0 版中的此操作仅支持用户的工作或学校邮箱,不支持个人邮箱。
使用GET Photo的 Beta 版可能会更好,因为它支持从 Exhange 邮箱和 AAD 配置文件中提取照片:
<cfhttp method="get" url="https://graph.microsoft.com/beta/users/{id}/photo/$value" result="resp" charset="utf-8">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="header" name="Authorization" value="bearer Oxfd989309sdf...">
</cfhttp>
推荐阅读
- python - 如何将文本导入DataFrame的列,跳过colspec(PYTHON)
- mysql - 简化递归mysql查询
- php - 我想要特定秒之前的日期时间
- python - Python在乘法时产生奇怪的小数
- go - go.mod 在修订版中有 post-v0 模块路径“git.example.com/owner/repo/v3”...?
- build - 如何找出 Visual Studio 2019 重建未修改的 .NET Core 项目的确切原因
- python - 在画布上创建可滚动表格
- cassandra - gremlin-groovy 不是可用的 GremlinScriptEngine
- ios - 想要将 b2b 应用程序转换为常规应用程序
- php - 如何在 PrestaShop 的 .tpl 文件中创建全局变量?