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

Azure AD B2C注册页面自定义与内置属性预填充及只读配置问询

Azure AD B2C自定义注册页面:预填充自定义属性并设置只读

一、预填充自定义属性实现方法

预填充数据需通过请求参数传递并在自定义策略中映射:

  • 跳转注册页面时,将用户数据作为查询参数附加到URL,例如:https://your-b2c-tenant.b2clogin.com/your-b2c-tenant.onmicrosoft.com/B2C_1A_signup_signin/oauth2/v2.0/authorize?client_id=xxx&response_type=code&redirect_uri=xxx&scope=openid&extension_CustomAttr1=预先填充的值&extension_CustomAttr2=另一预填充值
  • 在自定义策略的TrustFrameworkExtensions.xml中,找到注册对应的Technical Profile(通常是LocalAccountSignUpWithLogonEmail),添加InputClaim节点映射参数到自定义属性:
<ClaimsProvider>
  <DisplayName>Local Account SignUp</DisplayName>
  <TechnicalProfiles>
    <TechnicalProfile Id="LocalAccountSignUpWithLogonEmail">
      <InputClaims>
        <!-- 映射URL参数到自定义属性,DefaultValue用{OAUTH-KV:参数名}获取值 -->
        <InputClaim ClaimTypeReferenceId="extension_CustomAttr1" DefaultValue="{OAUTH-KV:extension_CustomAttr1}" />
        <InputClaim ClaimTypeReferenceId="extension_CustomAttr2" DefaultValue="{OAUTH-KV:extension_CustomAttr2}" />
      </InputClaims>
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>

二、设置自定义属性为只读

通过修改ClaimType定义实现前端只读限制:

  • 在自定义策略的TrustFrameworkExtensions.xml中,找到对应自定义属性的<ClaimType>节点,添加<UserInputType>Readonly</UserInputType>:
<ClaimType Id="extension_CustomAttr1">
  <DisplayName>自定义属性1</DisplayName>
  <DataType>string</DataType>
  <UserInputType>Readonly</UserInputType>
</ClaimType>
<ClaimType Id="extension_CustomAttr2">
  <DisplayName>自定义属性2</DisplayName>
  <DataType>string</DataType>
  <UserInputType>Readonly</UserInputType>
</ClaimType>
  • 额外说明:前端只读仅做界面限制,若要确保后端不接受修改,需保证在后续流程的Technical Profile中,该属性仅作为OutputClaim传递,不允许用户通过InputClaim提交新值。

三、前置准备与测试

  1. 先在Azure AD B2C门户的用户属性中创建目标自定义属性,系统会自动生成以extension_开头的属性ID
  2. 将自定义属性的定义添加到自定义策略的TrustFrameworkExtensions.xml中(若未自动包含)
  3. 发布更新后的自定义策略,构造带参数的注册URL进行测试,验证字段是否被预填充且无法编辑

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 18:10:34