创建AD用户并同时添加到组?

时间:2017-01-30 05:01:19

标签: azure azure-ad-b2c azure-ad-graph-api

我知道如何创建AD B2C用户,以及通过图形API将它们添加到组中。我在Azure功能中执行此操作。我想知道的是,是否可以创建用户并同时将它们添加到组中?如果没有,那么我想我将不得不处理用户被创建但未能添加到组的潜在情况。这种情况有多大可能?我试图确保我覆盖所有失败条件的所有基础,所以任何输入都将受到赞赏。感谢。

1 个答案:

答案 0 :(得分:1)

您似乎希望将Batch Processing用于此类请求。

以下是他们在文章中发布的示例请求: 以下示例显示了包含五个项目的批处理请求:

  1. 创建用户的更改集testuser@contoso.onmicrosoft.com(POST)。此操作包括Prefer:response-no-content标头,以禁止返回新创建的用户。
  2. 更新集,用于更新新用户(PATCH)的部门和职务属性,并设置其经理导航属性(PUT)。
  3. 查询新用户的管理员(GET)。
  4. 删除新用户的更改集(DELETE)。
  5. 用户查询(GET)。此操作将失败,因为在上一步中删除了用户。

    POST https://graph.windows.net/contoso.onmicrosoft.com/$batch?api-version=1.5 HTTP/1.1
    Authorization: Bearer ey … jQA
    Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b 
    Host: graph.windows.net
    Content-Length: 2961
    
    --batch_36522ad7-fc75-4b56-8c71-56071383e77b 
    Content-Type: multipart/mixed; boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd620 
    Content-Length: 631       
    
    --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd620 
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST /contoso.onmicrosoft.com/users?api-version=1.5 HTTP/1.1
    Content-Type: application/json
    Accept: application/json
    Content-Length: 256
    Prefer: return-no-content
    Host: graph.windows.net
    
    {
        "accountEnabled": true,
        "displayName": "Test User",
        "mailNickname": "testuser",
        "passwordProfile": { "password" : "Test1234", "forceChangePasswordNextLogin": false },
        "userPrincipalName": "testuser@contoso.onmicrosoft.com"
    }
    
    --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd620----batch_36522ad7-fc75-4b56-8c71-56071383e77b 
    Content-Type: multipart/mixed; boundary=changeset_4b2cbfb7-011d-4edb-8bbf-e044f9830aaf 
    Content-Length: 909
    
    --changeset_4b2cbfb7-011d-4edb-8bbf-e044f9830aaf 
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    PATCH /contoso.onmicrosoft.com/users/testuser@contoso.onmicrosoft.com?api-version=1.5 HTTP/1.1
    Content-Type: application/json
    Accept: application/json
    Content-Length: 72
    Host: graph.windows.net
    
    {
        "department": "Engineering",
        "jobTitle": "Test Engineer"
    }
    
    --changeset_4b2cbfb7-011d-4edb-8bbf-e044f9830aaf 
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    PUT /contoso.onmicrosoft.com/users/testuser@contoso.onmicrosoft.com/$links/manager?api-version=1.5 HTTP/1.1
    Content-Type: application/json
    Accept: application/json
    Content-Length: 112
    Host: graph.windows.net
    
    {
      "url":"https://graph.windows.net/contoso.onmicrosoft.com/users/a71e4d1c-ce99-40dc-8d4b-390eac63e039"
    }
    
    --changeset_4b2cbfb7-011d-4edb-8bbf-e044f9830aaf----batch_36522ad7-fc75-4b56-8c71-56071383e77b 
    Content-Type: application/http 
    Content-Transfer-Encoding:binary
    
    GET /contoso.onmicrosoft.com/users/testuser@contoso.onmicrosoft.com/$links/manager?api-version=1.5 HTTP/1.1
    Accept: application/json
    Host: graph.windows.net
    
    --batch_36522ad7-fc75-4b56-8c71-56071383e77b 
    Content-Type: multipart/mixed; boundary=changeset_9a0b5878-0f4a-4f57-91c5-9792cdd5ef20 
    Content-Length: 331       
    
    --changeset_9a0b5878-0f4a-4f57-91c5-9792cdd5ef20 
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    DELETE /contoso.onmicrosoft.com/users/testuser@contoso.onmicrosoft.com?api-version=1.5 HTTP/1.1
    Accept: application/json
    Host: graph.windows.net
    
    
    --changeset_9a0b5878-0f4a-4f57-91c5-9792cdd5ef20----batch_36522ad7-fc75-4b56-8c71-56071383e77b 
    Content-Type: application/http 
    Content-Transfer-Encoding:binary
    
    GET /contoso.onmicrosoft.com/users/testuser@contoso.onmicrosoft.com?api-version=1.5 HTTP/1.1
    Accept: application/json
    Host: graph.windows.net
    
    --batch_36522ad7-fc75-4b56-8c71-56071383e77b--