【问题标题】:Azure AD B2C REST API : Create Bulk Local AccountsAzure AD B2C REST API:创建批量本地帐户
【发布时间】:2020-03-26 07:15:20
【问题描述】:

是否可以通过 REST API 批量创建用户。与我们在以下 URL 中为单个用户所做的相同。

https://graph.windows.net/{MYADB2C}.onmicrosoft.com/users?api-version=1.6

我们通过 Azure 门户进行了配置,但无法使用 REST API 找到任何内容。

更新 批处理的示例请求

POST https://graph.windows.net/{}.onmicrosoft.com/$batch?api-version=1.6
Headers :
Authorization : {token}
Content-Type : multipart/mixed; boundary=changeset_***********

Body :
{
  "requests": [
    {
      "id": "1",
      "method": "POST",
      "url": "/users",
      "body": {
        "accountEnabled": true,
        "creationType": "LocalAccount",
        "displayName": "test1@gamil.com",
        "passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
        "passwordProfile": {
          "password": "***",
          "forceChangePasswordNextLogin": false
        },
        "signInNames": [
          {
            "type": "emailAddress",
            "value": "test1@gamil.com"
          }
        ]
      },
      "headers": {
        "Content-Type": "application/json"
      }
    },
    {
      "id": "2",
      "method": "POST",
      "url": "/users",
      "body": {
        "accountEnabled": true,
        "creationType": "LocalAccount",
        "displayName": "test2@gmail.com",
        "passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
        "passwordProfile": {
          "password": "***",
          "forceChangePasswordNextLogin": false
        },
        "signInNames": [
          {
            "type": "emailAddress",
            "value": "test1@gamil.com"
          }
        ]
      },
      "headers": {
        "Content-Type": "application/json"
      }
    }
  ]
}

【问题讨论】:

    标签: azure rest azure-active-directory


    【解决方案1】:

    是的。可以参考Batch processing | Graph API concepts进行批量操作。

    但我们建议您使用 Microsoft Graph API JSON Batching 而不是 Azure AD Graph 批处理,因为 Azure AD Graph 内容不再更新。

    此处使用 Microsoft Graph API 的示例:

    POST https://graph.microsoft.com/v1.0/$batch
    Accept: application/json
    Content-Type: application/json
    
    {
      "requests": [
        {
          "id": "1",
          "method": "POST",
          "url": "/users",
          "body": {
              "accountEnabled": true,
              "displayName": "at1",
              "mailNickname": "at1",
              "userPrincipalName": "at1@**.onmicrosoft.com",
              "passwordProfile" : {
                  "forceChangePasswordNextSignIn": true,
                  "password": "password-value"
              }
          },
          "headers": {
            "Content-Type": "application/json"
          }
        },
        {
          "id": "2",
          "method": "POST",
          "url": "/users",
          "body": {
              "accountEnabled": true,
              "displayName": "at2",
              "mailNickname": "at2",
              "userPrincipalName": "at2@**.onmicrosoft.com",
              "passwordProfile" : {
                  "forceChangePasswordNextSignIn": true,
                  "password": "password-value"
              }
          },
          "headers": {
            "Content-Type": "application/json"
          }
        },
        {
          "id": "3",
          "method": "POST",
          "url": "/users",
          "body": {
              "accountEnabled": true,
              "displayName": "at3",
              "mailNickname": "at3",
              "userPrincipalName": "at3@**.onmicrosoft.com",
              "passwordProfile" : {
                  "forceChangePasswordNextSignIn": true,
                  "password": "password-value"
              }
          },
          "headers": {
            "Content-Type": "application/json"
          }
        }
      ]
    }
    

    您可以在Microsoft Graph Explorer进行快速测试。

    【讨论】:

    • 谢谢艾伦,但我正在使用 Azure AD Graph API,您提供的参考资料仅适用于 Microsoft Graph API。
    • @coder89 是的。正如我在回答中提到的,不推荐使用 Azure AD Graph。如果您坚持,请参考我提供的第一个文档:docs.microsoft.com/en-us/previous-versions/azure/ad/graph/howto/…。这是 Azure AD Graph 批处理。
    • 了解,但是当我使用 Azure AD Graph API 进行批处理时,我没有收到任何响应,它只是返回 202 Accepted !这就是为什么我想知道是否还有其他我可以检查的参考。
    • @coder89 B2C租户中的用户创建成功了吗?您能出示您的请求详情吗?
    • 否,用户未在 AD B2C 中创建。我已通过示例批处理请求更新了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    相关资源
    最近更新 更多