azure - 如何使用 Microsoft Graph API 更新 Azure AD 中的现有用户

标签 azure azure-active-directory microsoft-graph-api

我已在 azure 广告中添加了用户。现在使用 graph api 我想更新其显示名称或密码。我指的是本指南https://learn.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=cs

首先,我不确定我是否使用正确的 URL 来更新用户,但以下是我正在使用的:

 https://graph.microsoft.com/v1.0/users/john@<myorg>.onmicrosoft.com

我正在传递我想要在网址中更新的用户的userName。如果这不正确,请告诉我。

我将 OAuth token 作为不记名 token 包含在我的请求中,并发布以下 json:

{
  "accountEnabled": true,

  "displayName": "john12"

}

根据上面的 json,我想将显示名称从 john 更改为 john12。但我收到以下错误:

{
    "error": {
        "code": "Request_BadRequest",
        "message": "Specified HTTP method is not allowed for the request target.",
        "innerError": {
            "request-id": "536fd7c1-db46-4927-9732-169da778811c",
            "date": "2019-06-06T04:58:26"
        }
    }
}

请问谁可以告诉我如何更新现有的用户属性。谢谢

最佳答案

很可能您没有使用 HTTP 方法 PATCH。我说这个是看错误消息请求目标不允许指定的HTTP方法。

如果您使用 PATCH 以外的任何内容,例如 POST,您最终将收到此错误消息。

您的请求的 JSON 正文看起来不错。我尝试使用类似的 JSON 更新现有用户,并从 Microsoft Graph Explorer 发送 PATCH 请求。并且效果很好。

我可以重现您在使用 Microsoft Graph Explorer 中的 POST 或 PUT 调用时看到的相同错误消息。

enter image description here

尽管在我将 POST 更改为 PATCH 后,具有相同 JSON 正文的相同请求 URL 工作正常。稍后再次查询用户 (GET),我可以看到 displayName 已正确更新

enter image description here

关于azure - 如何使用 Microsoft Graph API 更新 Azure AD 中的现有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56471145/

相关文章:

azure - Windows Azure 帐户的多个管理员

azure - 在 Azure 中,如何使两个事件目录共享同一个应用程序?

java - 找不到 ClientRegistrationRepository Bean

c# - 基于 asp.net mvc 和 azure Active Directory 安全组的授权

mysql - Azure Database for MySQL - 单一服务器的备份状态警报

c# - 尝试在 azure 存储帐户/Blob 上设置 cors 时出现无尽错误

c# - 将安全组添加到安全组失败 Request_BadRequest

microsoft-graph-api - Microsoft Graph API - 503 ErrorServiceUnavailable

azure - 通过 powershell 将应用程序见解链接到 Azure Web 应用程序

c# - 通过 Graph API 创建团队时出现 BadRequest 或冲突