You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何排查Azure B2C IEF用户旅程中的500内部服务器错误?

碰到Azure B2C IEF的500内部服务器错误确实头疼,尤其是Application Insights还没给出有效线索的时候。我帮你梳理几个排查方向,大概率能找到问题根源:

排查Azure B2C IEF 500错误的关键步骤

1. 补全自断言Technical Profile的必填配置

你当前的Step1 Technical Profile用了SelfAssertedAttributeProvider,这类配置有几个容易漏掉的必填项,缺了就会直接触发500错误:

  • 没有指定<Metadata>里的ContentDefinitionReferenceId:这是关联UI模板的核心参数,IEF找不到页面模板就会崩溃
  • 缺少<InputClaims>节点:哪怕不需要输入任何声明,也得显式加上空节点,否则引擎会报错
  • 可能没加密码验证的ValidationTechnicalProfiles:注册场景下需要验证密码并写入AAD,这一步不能少

修正后的配置参考:

<TechnicalProfile Id="Step1">
  <DisplayName>Step 1</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  <Metadata>
    <!-- 绑定默认的自断言注册UI模板 -->
    <Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
    <Item Key="EnforceEmailVerification">False</Item>
  </Metadata>
  <InputClaims>
    <!-- 空节点即可,无需内容 -->
  </InputClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="Email" Required="true"/>
    <OutputClaim ClaimTypeReferenceId="newPassword" Required="true" />
    <OutputClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
  </OutputClaims>
  <!-- 添加密码验证与用户写入的Technical Profile -->
  <ValidationTechnicalProfiles>
    <ValidationTechnicalProfile ReferenceId="AAD-UserWriteUsingLogonEmail" />
  </ValidationTechnicalProfiles>
</TechnicalProfile>

2. 确认Claims Schema的定义正确

要确保你在策略的<ClaimsSchema>里已经完整定义了emailnewPasswordreenterPassword这几个声明类型,比如:

<ClaimsSchema>
  <ClaimType Id="email">
    <DisplayName>Email Address</DisplayName>
    <DataType>string</DataType>
    <UserHelpText>Enter your email address</UserHelpText>
    <UserInputType>TextBox</UserInputType>
  </ClaimType>
  <ClaimType Id="newPassword">
    <DisplayName>New Password</DisplayName>
    <DataType>string</DataType>
    <UserHelpText>Enter a password that meets our requirements</UserHelpText>
    <UserInputType>Password</UserInputType>
  </ClaimType>
  <ClaimType Id="reenterPassword">
    <DisplayName>Re-enter Password</DisplayName>
    <DataType>string</DataType>
    <UserHelpText>Confirm your password</UserHelpText>
    <UserInputType>Password</UserInputType>
  </ClaimType>
</ClaimsSchema>

如果某个声明类型没定义或者DataType、UserInputType配置错了,引擎处理时就会抛出500错误。

3. 开启Application Insights的详细日志

你说没拿到错误信息,大概率是日志级别不够。在策略的<RelyingParty>部分加上这段配置,开启开发者模式的详细日志:

<RelyingParty>
  <DefaultUserJourney ReferenceId="YourUserJourneyId" />
  <TechnicalProfile Id="PolicyProfile">
    <DisplayName>PolicyProfile</DisplayName>
    <Protocol Name="OpenIdConnect" />
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="email" />
    </OutputClaims>
    <SubjectNamingInfo ClaimType="email" />
  </TechnicalProfile>
  <UserJourneyBehaviors>
    <JourneyInsights TelemetryEngine="ApplicationInsights" 
                    InstrumentationKey="你的AI密钥" 
                    DeveloperMode="true" 
                    ClientEnabled="false" 
                    ServerEnabled="true" 
                    TelemetryVersion="1.0.0" />
  </UserJourneyBehaviors>
</RelyingParty>

DeveloperMode="true"会生成包含错误堆栈的详细日志,你可以在Application Insights的“跟踪”里搜索SeverityLevel:Error,就能找到具体的错误原因了。

4. 检查用户旅程的步骤依赖

你的编排步骤是Order="3",跳过条件是objectId存在。要确保前面的步骤(Order=1、2)没有出错,比如是否正确初始化了会话上下文,或者有没有其他步骤的ClaimsExchange失败导致后续流程中断。

5. 用Azure Portal的策略验证工具

上传策略时,Azure Portal的IEF策略管理页面会自动验证配置语法和逻辑,很多时候会直接指出哪里有问题,比如缺少某个节点、引用的Technical Profile不存在等,这是最快排查语法错误的方法。


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

火山引擎 最新活动