通过 graph api 或 graph sdk 为整个 B2C 实例创建用户自定义属性

Create user custom attribute for whole B2C instance via graph api or graph sdk

我想通过图形 api 或 sdk 为整个 b2c 实例创建 'user custom attribute'。就像我在下面引用的 ms documentation 之后通过 Azure 门户所做的那样。

1. Sign in to the Azure portal as the global administrator of your Azure AD B2C tenant.
2. Make sure you're using the directory that contains your Azure AD B2C tenant by switching to it in the top-right corner of the Azure portal. 
3. Select your subscription information, and then select Switch Directory.
4. Choose All services in the top-left corner of the Azure portal, search for and select Azure AD B2C.
5. Select User attributes, and then select Add.
6. Provide a Name for the custom attribute (for example, "ShoeSize")
7. Choose a Data Type. Only String, Boolean, and Int are available.
8. Optionally, enter a Description for informational purposes.
9. Click Create.

需要说明的是,我不想创建具有自定义属性的用户,而是为 b2c 中的所有用户创建一个自定义属性。

我可以做吗?如果可以,怎么做?

您可以使用 Create extensionProperty 为整个 b2c 实例创建 'user custom attribute'。

请注意,我们需要将 targetObjects 指定为“用户”。

一个例子:

Post https://graph.microsoft.com/v1.0/applications/{object id of the Azure AD application}/extensionProperties

{"name":"customAttribute","dataType":"string","targetObjects":["User"]}

它将生成一个名为 extension_{client id of the Azure AD application without "-"}_customAttribute 的扩展 属性。

然后您可以为您的任何 B2C 帐户更新扩展名 属性:

Patch https://graph.microsoft.com/v1.0/users/{user id}

{"extension_{client id of the Azure AD application without "-"}_customAttribute":"value"}

请注意:

你在 Azure 门户上创建的用户自定义属性与名为 b2c-extensions-app. Do not modify. Used by AADB2C for storing user data. 的 Azure AD 应用关联,你可以在 Azure AD B2C 下找到它 -> 应用程序注册 -> 所有应用程序.

但是您使用 Microsoft Graph 创建的自定义属性不会出现在 Azure 门户上 |用户属性 无论您是在 b2c-extensions-app 下还是在任何其他 Azure AD 应用程序下创建自定义属性。