首页 > 解决方案 > 在 Graph 中检索照片时从 Microsoft 获取“AuthenticationError”

问题描述

我正在使用仅限应用程序权限查询 Microsoft Graph,因为我正在对目录中的所有用户执行操作。当我onPremisesSamAccountName用我的令牌查询时,我没有问题。但是,当我尝试为用户检索照片时(使用相同的令牌),我得到以下信息:

StatusCode: 400 Bad Request
Error Code: AuthenticationError
Error Message: Error authenticating with resource

我在租户中分配了以下仅限应用的权限:

细节:

这是我的要求(在 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

我错过了一步,还是遗漏了一个范围?

标签: azureazure-active-directorymicrosoft-graph-api

解决方案


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>

推荐阅读