Azure AD B2C本地账户自定义注册策略表单缺失givenName输入项
解决Azure B2C自定义策略注册表单不显示givenName输入框的问题
要让givenName(名字)输入框显示在注册表单中,你需要修改注册流程对应的技术配置文件(TechnicalProfile),仅在RelyingParty部分声明输出项不会触发前端输入框渲染。具体操作步骤如下:
1. 定位注册用的TechnicalProfile
在你的自定义策略文件(通常是TrustFrameworkBase.xml或自定义扩展文件)中,找到负责本地账户注册的TechnicalProfile,默认ID为LocalAccountSignUpWithLogonEmail。
2. 添加InputClaims声明
在该TechnicalProfile的<InputClaims>节点下,添加givenName的输入声明,注册页面会自动渲染对应的输入框:
<InputClaims> <!-- 原有输入项,保留不动 --> <InputClaim ClaimTypeReferenceId="email" /> <!-- 添加givenName输入项,Required标记为必填(可按需调整) --> <InputClaim ClaimTypeReferenceId="givenName" Required="true" /> <!-- 如果需要显示姓氏(surname),同样添加该声明 --> <InputClaim ClaimTypeReferenceId="surname" Required="true" /> </InputClaims>
3. 配置PersistedClaims保存用户数据
为了让用户输入的givenName保存到Azure AD B2C用户目录中,需要在同一TechnicalProfile的<PersistedClaims>节点下添加对应声明:
<PersistedClaims> <!-- 原有持久化项,保留不动 --> <PersistedClaim ClaimTypeReferenceId="email" PartnerClaimType="signInNames.emailAddress" /> <!-- 添加givenName和surname的持久化声明 --> <PersistedClaim ClaimTypeReferenceId="givenName" /> <PersistedClaim ClaimTypeReferenceId="surname" /> <!-- 其他原有项如password等,保留不动 --> </PersistedClaims>
4. 验证用户旅程配置
确认你的SignUpOrSignIn用户旅程中,注册步骤引用的是上述修改后的TechnicalProfile。入门包默认配置通常是正确的,示例参考:
<UserJourney Id="SignUpOrSignIn"> <!-- 其他步骤保留不动 --> <OrchestrationStep Order="2" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimsExist" ExecuteActionsIf="true"> <Value>objectId</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="LocalAccountSignUp" TechnicalProfileReferenceId="LocalAccountSignUpWithLogonEmail" /> </ClaimsExchanges> </OrchestrationStep> <!-- 其他步骤保留不动 --> </UserJourney>
完成上述修改后,重新上传自定义策略,注册页面就会显示givenName及你添加的其他输入项。
内容的提问来源于stack exchange,提问作者AndrewO
相关产品推荐
相关产品推荐

