如何使用 Graph REST API 更新 Azure AD 中用户的 hireDate 属性?

问题描述 投票:0回答:1

我搜索了类似的问题,但没有找到我想要的答案。

我的目标是更新 AAD 中所有用户的 hireDate。

起初,我尝试使用客户端凭证流来实现这一目标。

POST https://login.microsoftonline.com/espiradev.onmicrosoft.com/oauth2/token
Content-Type:application/x-www-form-urlencoded

grant_type:client_credentials
client_id:{{client_id}}
client_secret:{{client_secret}}
resource:https://graph.microsoft.com

当我得到访问代码后,我打电话给他。

PATCH https://graph.microsoft.com/v1.0/users/[user1]
Authorization:bearer {{access_token}}
Content-Type:application/json
{
 "hireDate": "2019-05-01T00:00:00Z"
}

响应。

"error": {
  "code": "-1, Microsoft.Office.Server.Directory.DirectoryObjectUnauthorizedAccessException",
  "message": "Attempted to perform an unauthorized operation.",
  "innerError": {}
}

第二次尝试是使用密码流(客户端和用户凭证)。我使用我的全局管理员[user1]凭证并调用相同的HTTP请求。响应是 HTTP 204 (一切正常)。

POST https://login.microsoftonline.com/espiradev.onmicrosoft.com/oauth2/token
Content-Type:application/x-www-form-urlencoded

grant_type:password
client_id:{{client_id}}
client_secret:{{client_secret}}
resource:https://graph.microsoft.com
username:{{user1_upn}}
password:{{user1_password}}

不幸的是,当我试图更新其他[user2]时,结果是这样的。

PATCH https://graph.microsoft.com/v1.0/users/[user2]
Authorization:bearer {{access_token}}
Content-Type:application/json
{
  "hireDate": "2019-05-01T00:00:00Z"
}

响应:

"error": {
   "code": "-1, Microsoft.Office.Server.Directory.DirectoryObjectUnauthorizedAccessException",
   "message": "Attempted to perform an unauthorized operation.",
   "innerError": {}
}

如果我使用[user2]的凭证来获取访问令牌,那么我可以更新[user2]的hireDate,但不能更新[user1]。

应用权限。应用权限:

已更新。Decoded access token has these permissions:

"scp": "Directory.AccessAsUser.All Directory.ReadWrite.All User.ManageIdentities.All User.ReadWrite User.ReadWrite.All"

UPDATED[2]。用户1]和[用户2]都已分配了Office 365 E1许可证(包括SharePoint Online(计划1))。

我是不是做错了什么?如果谁有解决方法可以分享,那就非常感谢了。

microsoft-graph
1个回答
0
投票

除了办公许可,全局管理用户在令牌中应该有Sites.ReadWrite.All范围权限,才能为其他用户更新 "hireDate "属性。

© www.soinside.com 2019 - 2024. All rights reserved.