我正在尝试通过服务器端(Java)应用程序通过Microsoft Graph API更新用户配置文件,而无需用户同意 . 我在MS Azure中有一个应用程序,它具有以下“对其他应用程序的权限": " Microsoft Graph - 读取和写入所有用户的完整配置文件" as an "应用程序权限”,管理员已同意这些设置 .
所以我可以从我们的租户那里获取任何用户 Profiles . 此外,通过“所有邮箱中的读写日历”权限,我可以列出并修补用户的日历条目 . 使用相同的代码snipets来更新用户配置文件但不起作用 .
这是工作流的REST表示,
获取访问令牌:
POST https://login.microsoftonline.com/<my-tenant>/oauth2/token
Content-Type: application/x-www-form-urlencoded
{
grant_type=client_credentials
&resource=https%3A%2F%2Fgraph.microsoft.com
&client_secret=<my-client-secret>
&client_id=<my-client-id>
}
到目前为止这么好,补丁用户档案:
PATCH https://graph.microsoft.com/v1.0/<my-tenant>/users/<target-user>
Authorization: Bearer <access_token from prev response>
Accept: application/json
Content-Type: application/json
{"aboutMe": "happy"}
响应是:
response code: 500
{
"error": {
"code": "-1, Microsoft.Office.Server.Directory.DirectoryObjectUnauthorizedAccessException",
"message": "Attempted to perform an unauthorized operation.",
"innerError": {
"request-id": "<request-id>",
"date": "2016-09-27T11:07:18"
}
}
}
根据http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_update文档,我应该设置“User.ReadWrite; User.ReadWrite.All; Directory.ReadWrite.All " scopes, unfortunately there is no such thing at manage.windowsazure.com app setting page but I believe "读取并写入所有用户的完整配置文件”应该可以解决问题 . 上面的示例请求将某些数据替换为<>标记,在正常工作流程中它们可以正确填充 . 它非常适合修补日历事件(除了URL中的一个小的更改,几乎完全相同)但是修补用户对象失败了 .
2 回答
我也可以重现这个问题 .
根据测试,该问题与我们正在更新的特定字段( aboutMe )有关 . 当我使用 Directory.ReadWrite.All 更新 jobTitle 时,补丁用户API对我很有用 .
如果您希望Microsoft Graph支持更新 aboutMe 字段,您可以从here提交反馈 .
Microsoft Graph目前在用户和组的操作方面存在一些限制,具体取决于权限类型 . 根据网站Known issues,你可以发现有一个限制:
Cannot perform any CRUD operations on User other than updating user HD photo and extended profile properties
适用于Delegated
和Application
权限类型 .选择
Directory.ReadWrite.All
权限(new Azure portal中的Read and write directory data
),如Microsoft Graph permissions部分表中的Alternative
列所示,应该可以解决问题 .