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提交新值。
三、前置准备与测试
- 先在Azure AD B2C门户的用户属性中创建目标自定义属性,系统会自动生成以
extension_开头的属性ID - 将自定义属性的定义添加到自定义策略的
TrustFrameworkExtensions.xml中(若未自动包含) - 发布更新后的自定义策略,构造带参数的注册URL进行测试,验证字段是否被预填充且无法编辑
内容的提问来源于stack exchange,提问作者Juliyanage Silva
相关产品推荐
相关产品推荐

