如何为 Azure AD B2B 用户添加自定义属性

问题描述

如何使用 API 在 Azure AD B2B 中为用户添加自定义属性

A 找到了 External Identities方法,但我正在寻找自定义属性,而不管用户类型如何。 例如,我想为每个用户(成员或访客)设置“FavoriteColor”属性

我怎样才能做到这一点?

解决方法

您可以使用 Microsoft Graph API Create extensionProperty

targetObjects 指定为“用户”。

示例(您可以将任何应用注册用于 {object id of the app registration}):

Post https://graph.microsoft.com/v1.0/applications/{object id of the app registration}/extensionProperties

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

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

然后您可以更新成员或访客用户的扩展属性:

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

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

使用 Microsoft Graph Explorer 进行快速测试。

Microsoft Graph auth overviewMicrosoft Graph SDK 供您参考。