Azure B2C自定义策略:两步注册移除写入验证后遇服务器错误
两步注册流程移除第一步用户写入验证配置后出现服务器错误问题
问题描述
我正尝试创建一个两步注册流程,计划在第二步将用户写入目录。但当注释掉第一步中用于写入目录的验证技术配置文件(AAD-UserWriteUsingLogonEmail)后,执行流程时出现服务器错误。点击登录页的“创建账户”按钮时,页面提示“由于发生内部服务器错误,无法显示页面”。我想了解问题原因,第一步是否仅能收集输入?我已将自断言配置简化为仅收集邮箱,实际需要收集更多声明,希望解决此障碍后再实现。
相关技术配置代码:
<TechnicalProfile Id="LocalAccountSignUpWithEmailStep1"> <DisplayName>Email signup</DisplayName> <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> <Metadata> <Item Key="IpAddressClaimReferenceId">IpAddress</Item> <Item Key="ContentDefinitionReferenceId">api.mholocalaccountsignupstep1</Item> <Item Key="language.button_continue">Next Step</Item> <Item Key="EnforceEmailVerification">False</Item> </Metadata> <CryptographicKeys> <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" /> </CryptographicKeys> <InputClaims> <InputClaim ClaimTypeReferenceId="email" /> </InputClaims> <OutputClaims> <OutputClaim ClaimTypeReferenceId="objectId" /> <OutputClaim ClaimTypeReferenceId="email" **** ADDING OR REMOVING PartnerClaimType DOES NOT FIX THE ISSUE PartnerClaimType="Verified.Email" ***** Required="true" /> <OutputClaim ClaimTypeReferenceId="executed-SelfAsserted-Input" DefaultValue="true" /> </OutputClaims> <!-- REMOVING THIS BLOCK ENDS UP WITH SERVER ERROR <ValidationTechnicalProfiles> <ValidationTechnicalProfile ReferenceId="AAD-UserWriteUsingLogonEmail" /> </ValidationTechnicalProfiles> --> <UseTechnicalProfileForSessionManagement ReferenceId="SM-AAD" /> </TechnicalProfile>
问题原因及解决方案
核心问题
objectId声明缺失:第一步技术配置输出了objectId,但移除用户写入验证配置后,没有逻辑生成该值。而SM-AAD会话管理组件依赖objectId维持会话,缺失会触发服务器错误。- 会话管理组件不匹配:
SM-AAD是针对已存在的Azure AD用户设计的会话管理,第一步未创建用户,没有有效用户标识,导致组件无法正常工作。
修复步骤
- 移除无效的
objectId输出声明:第一步仅做输入收集,不需要输出用户标识,删除<OutputClaim ClaimTypeReferenceId="objectId" />。 - 更换会话管理组件:改用无操作的会话管理
SM-Noop,替换<UseTechnicalProfileForSessionManagement ReferenceId="SM-AAD" />为<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />。 - 第二步处理用户创建:在第二步的技术配置中添加
AAD-UserWriteUsingLogonEmail验证配置,确保用户在第二步被写入目录并生成objectId,之后再切换回SM-AAD会话管理。
修改后的第一步技术配置示例:
<TechnicalProfile Id="LocalAccountSignUpWithEmailStep1"> <DisplayName>Email signup</DisplayName> <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> <Metadata> <Item Key="IpAddressClaimReferenceId">IpAddress</Item> <Item Key="ContentDefinitionReferenceId">api.mholocalaccountsignupstep1</Item> <Item Key="language.button_continue">Next Step</Item> <Item Key="EnforceEmailVerification">False</Item> </Metadata> <CryptographicKeys> <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" /> </CryptographicKeys> <InputClaims> <InputClaim ClaimTypeReferenceId="email" /> </InputClaims> <OutputClaims> <OutputClaim ClaimTypeReferenceId="email" Required="true" /> <OutputClaim ClaimTypeReferenceId="executed-SelfAsserted-Input" DefaultValue="true" /> </OutputClaims> <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" /> </TechnicalProfile>
补充说明
第一步完全可以仅用于收集输入,核心是确保会话管理组件和输出声明与当前流程阶段匹配,不要引入未被填充的用户标识类声明,避免会话管理因依赖缺失报错。
内容的提问来源于stack exchange,提问作者Erkan Y.
相关产品推荐
相关产品推荐

