首页 > 解决方案 > 使用 Graph 在 Azure B2C 中预创建联合用户

问题描述

是否可以通过 Graph API 在 Azure B2C 中预先创建联合用户?这是场景:

我已将 Azure AD 租户作为 IdP 添加到我的 B2C 租户。但是,我不希望联合用户能够注册。我希望他们只有在 B2C 目录中已经存在时才能登录。因此,如果不是,他们会收到一条错误消息。所以我想我可以使用 Graph 创建联合用户。以下是我尝试使用的请求正文,但出现以下错误,说明 UPN 必须使用组织中的域之一。是否可以通过 Graph 实现我希望实现的目标?如果不是通过 Graph API,我该如何完成?不需要自定义策略中的 REST API 调用。

{
    "givenName": "John",
    "identities": [
        {
            "signInType": "federated",
            "issuer": "abc.com",
            "issuerAssignedId": "jdoe@abc.com"
        }
    ],
    "surName": "Doe",
    "mail": "jdoe@abc.com",
    "accountEnabled": true,
    "displayName": "John Doe",
    "mailNickname": "jdoe",
    "userPrincipalName": "jdoe@abc.com",
    "passwordPolicies": "DisablePasswordExpiration"
}

{

    "error": {
        "code": "Request_BadRequest",
        "message": "The domain portion of the userPrincipalName property is invalid. You must use one of the verified domain names in your organization.",
        "innerError": {
            "date": "2020-08-05T03:45:26",
            "request-id": "xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxx"
        },
        "details": [
            {
                "target": "userPrincipalName",
                "code": "InvalidValue"
            }
        ]
    }
}
 

标签: azure-active-directoryazure-ad-b2c

解决方案


删除"userPrincipalName": "jdoe@abc.com",将解决此问题。

Microsoft Graph 似乎不允许我们userPrincipalName在为 Azure B2C 创建用户时进行设置。它将生成userPrincipalNameas {object id}@abc.com

然后你可以更新userPrincipalName.

PATCH https://graph.microsoft.com/v1.0/users/{object id}

{"userPrincipalName":"jdoe@abc.com"}

推荐阅读