如何填充 Azure Active Directory B2C 用户自定义用户属性?

How to populate Azure Active Directory B2C user custom user attributes?

我已经成功地使用 curl 来获取和更新我的 Azure Active Directory 租户中用户的邮政编码,命令如下:

curl -X GET https://graph.microsoft.com/v1.0/users/<userGuid>?$select=displayName,givenName,postalCode,xyz -H "Authorization: Bearer $AAD_BEARER_TOKEN"

这显示了 displayName、givenName 和 postalCode,但忽略了我在 portal.azure.com.

使用 Web 浏览器 UI 创建的自定义字符串属性 xyz

请注意,由于我在 windows 上使用 cygwin bash,因此我必须转义我的美元和符号。

如何使用 curl 填充我创建的名为 xyz 的新字段?

我试过 using open extensions 但示例不起作用(可能是因为它们不包含不记名令牌并且没有指定特定用户)。我可以期待看到我在 portal.azure.com 上使用 Web UI 创建的自定义属性“xyz”出现吗?

curl -X GET https://graph.microsoft.com/v1.0/me?$select=id,displayName,mail,mobilePhone\&$expand=extensions

这给了我“InvalidAuthenticationToken”。当我添加不记名令牌时,我得到

Resource '1acbf9cc-d931-4ff3-bafe-218693fba30e' does not exist or one of its queried reference-property objects are not present.

2021 年 3 月 2 日星期二晚上更新:

真丢脸!我忘记了最重要的问题:如何 post/patch 一个新值,以便我有东西可以获取 (GET)?我无法判断 GET 是否正常工作,因为该值为空。

2021 年 3 月 3 日星期三上午更新: 我终于找到了 the docs on custom attributes,它说我需要在 TrustFrameworkExtensions.xml 中修改我的自定义策略。斯坦利:这是你做的吗?我不清楚 InputClaims、PersistClaims 和 OutputClaims 的 XML。我需要编辑这个 XML 并上传吗?

据我了解,您想通过 Microsoft Graph API.

获取用户的自定义属性值

如果是这样,$select参数中的属性xyz应该是:extension_<your B2C application ID remove all '-' characters>_xyz

在我这边,我可以在这里找到我的 B2C 应用程序 ID:

我有一个自定义属性 id4GTM

如果我想获取用户的值,属性名应该是:extension_48c33b45c4f8419eb9d97a0f3ff1817b_id4GTM,请求URL应该是:

GET https://graph.microsoft.com/v1.0/users/8bbd6746-02c7-41a6-97ca-c745c8d27a23?$select=displayname,extension_48c33b45c4f8419eb9d97a0f3ff1817b_id4GTM

结果:

更新:

如果您想通过 Micorsoft Graph API 为用户设置 B2C 自定义属性,请尝试以下请求:

请求URL:

PATCH https://graph.microsoft.com/v1.0/users/<user guid>

请求正文:

{"extension_d98794e6f3ca42a6b755d6f9cca552e1_xyz": "<value you want to set>"}

我这边如下:

尝试获取这个值:

如果您还有其他问题,请告诉我:)