使用Graph API B2C将用户添加到组

时间:2019-05-27 06:23:07

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

我正在使用Azure AD B2C创建用户。 创建用户后,我要将其添加到网上论坛

使用邮递员,我提出了以下请求(标头中带有访问令牌)。注意:我已经成功使用Api成功创建了一个网上论坛。

开机自检 https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members/$ref?api-version=1.6

随身:

{
    "@odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}

文档指定的是哪个。无论发送的是尸体,都会出现以下错误

{
    "odata.error": {
        "code": "Request_BadRequest",
        "message": {
            "lang": "en",
            "value": "The request URI is not valid. Since the segment 'members' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource."
        },
        "requestId": "48cf65f3-20ba-411e-8121-f7ea54252f3a",
        "date": "2019-05-27T06:09:25"
    }
}

我尝试删除/ $ ref

开机自检 https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members?api-version=1.6

身体:

{
    "@odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}

以及

{
    "@odata.id": "https://graph.windows.net/{azure-tenant}/users/{user-objectId}"
}

现在返回的错误是:

{
    "odata.error": {
        "code": "Request_BadRequest",
        "message": {
            "lang": "en",
            "value": "Unsupported resource type 'DirectoryObject' for operation 'Create'."
        },
        "requestId": "2c36cc6d-383c-44f8-8609-2ac3e3efc862",
        "date": "2019-05-27T06:15:26"
    }
}

我一直在使用https://docs.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=javascript

的文档

1 个答案:

答案 0 :(得分:0)

您正在使用 graph.windows.net 终结点,因此您应该参考azure ad graph api

POST https://graph.windows.net/myorganization/groups/b4bda672-1fba-4711-8fb1-5383c40b2c14/$links/members?api-version=1.6

{
  "url": "https://graph.windows.net/myorganization/directoryObjects/3eb6055a-baeb-44d4-a1ea-2fee86d8891b"
}

您所指的document是Microsoft graph api。端点应为https:// graph.microsoft.com

您可以使用Microsoft Graph explorer来调用这些api。

enter image description here

enter image description here