You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure B2C自定义策略:如何在用户旅程中从令牌写入自定义属性

在Azure B2C自定义策略中将REST API返回值写入用户自定义属性

步骤1:确认自定义属性已在租户中创建

先在Azure AD B2C租户的用户属性界面,创建你需要存储的自定义属性(例如命名为customUserAttribute)。

步骤2:在自定义策略中声明对应声明

打开TrustFrameworkExtensions.xml,在<ClaimsSchema>节点下添加对应声明的定义,确保数据类型和你要存储的值匹配:

<ClaimType Id="customUserAttribute">
  <DisplayName>自定义用户属性</DisplayName>
  <DataType>string</DataType>
  <UserHelpText>存储从REST API获取的自定义值</UserHelpText>
</ClaimType>

步骤3:映射REST API的输出到声明

在你已配置的REST API连接器技术配置中,添加输出声明映射,把API返回的字段绑定到上面声明的Claim:

<TechnicalProfile Id="REST-YourAPIConnector">
  <!-- 其他已有配置 -->
  <OutputClaims>
    <!-- 其他已有输出声明 -->
    <OutputClaim ClaimTypeReferenceId="customUserAttribute" PartnerClaimType="apiReturnedValue" />
  </OutputClaims>
</TechnicalProfile>

这里apiReturnedValue替换为你的REST API实际返回的字段名。

步骤4:添加用户属性写入的编排步骤

在用户旅程中,找到调用REST API的编排步骤之后,添加一个调用Azure AD写入技术配置的步骤,用于将声明值持久化到用户存储:

<OrchestrationStep Order="NextOrderNumber" Type="ClaimsExchange">
  <ClaimsExchanges>
    <ClaimsExchange Id="WriteUserAttribute" TechnicalProfileReferenceId="AAD-UserWriteProfileUsingObjectId" />
  </ClaimsExchanges>
</OrchestrationStep>
  • 若处理新用户注册场景,可根据账户类型选择AAD-UserWriteUsingEmailAddress(本地账户)或AAD-UserWriteUsingAlternativeSecurityId(社交账户)作为技术配置ID。
  • 若更新现有用户属性,使用AAD-UserWriteProfileUsingObjectId即可。

步骤5:配置AAD技术配置的持久化声明

修改对应的Azure AD技术配置,添加要持久化的自定义属性到<PersistedClaims>节点:

<TechnicalProfile Id="AAD-UserWriteProfileUsingObjectId">
  <!-- 其他已有配置 -->
  <PersistedClaims>
    <!-- 其他已有持久化声明 -->
    <PersistedClaim ClaimTypeReferenceId="customUserAttribute" />
  </PersistedClaims>
</TechnicalProfile>

验证结果

运行用户旅程完成后,在Azure AD B2C的用户列表中找到目标用户,查看其自定义属性,确认REST API返回的值已成功写入。

内容的提问来源于stack exchange,提问作者atr4st

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 14:40:33