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

Azure B2C自定义策略首登未跳转改密页问题求助

问题排查与修复方案

核心问题分析

你遇到的现象是因为自定义策略中未正确读取用户的forceChangePasswordNextSignIn属性,且用户旅程的判断逻辑顺序、条件错误,导致策略无法识别用户需要强制改密的状态,反而触发了默认的密码过期提示。


具体修复步骤

1. 修复用户属性读取逻辑

自定义策略需要从Azure B2C目录中读取passwordProfile.forceChangePasswordNextSignIn属性,否则后续判断会失效。修改以下两个TechnicalProfile:

修改AAD-UserReadUsingSignInName
<TechnicalProfile Id="AAD-UserReadUsingSignInName">
  <Metadata>
    <Item Key="Operation">Read</Item>
  </Metadata>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="signInName" PartnerClaimType="signInNames.emailAddress" Required="true" />
  </InputClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="objectId" />
    <!-- 添加以下字段读取目录中的强制改密标志 -->
    <OutputClaim ClaimTypeReferenceId="forceChangePasswordNextSignIn" PartnerClaimType="passwordProfile.forceChangePasswordNextSignIn" />
  </OutputClaims>
  <IncludeTechnicalProfile ReferenceId="AAD-Common" />
</TechnicalProfile>
修改AAD-UserReadUsingObjectId
<TechnicalProfile Id="AAD-UserReadUsingObjectId">
  <!-- 原有配置 -->
  <OutputClaims>
    <!-- 保留原有输出字段,添加以下字段 -->
    <OutputClaim ClaimTypeReferenceId="forceChangePasswordNextSignIn" PartnerClaimType="passwordProfile.forceChangePasswordNextSignIn" />
  </OutputClaims>
</TechnicalProfile>

2. 调整用户旅程的强制改密步骤

原策略中步骤3的逻辑完全错误(存在该Claim就跳过),需要将强制改密判断移到读取用户属性之后,并设置正确的触发条件:

删除原步骤3,在步骤6(用户属性读取完成)后插入新的步骤7(后续步骤序号依次后移):

<!-- 步骤6之后插入:强制改密判断与执行 -->
<OrchestrationStep Order="7" Type="ClaimsExchange">
  <Preconditions>
    <!-- 只有当forceChangePasswordNextSignIn为true时,才执行改密步骤 -->
    <Precondition Type="ClaimEquals" ExecuteActionsIf="false">
      <Value>forceChangePasswordNextSignIn</Value>
      <Value>true</Value>
      <Action>SkipThisOrchestrationStep</Action>
    </Precondition>
  </Preconditions>
  <ClaimsExchanges>
    <ClaimsExchange Id="ForcePasswordReset" TechnicalProfileReferenceId="SelfAsserted-ForcePasswordReset" />
  </ClaimsExchanges>
</OrchestrationStep>

3. 修复改密后的属性重置逻辑

确保改密完成后,将目录中的forceChangePasswordNextSignIn设为false,避免重复触发:

<TechnicalProfile Id="AAD-UserWritePasswordUsingObjectId-ResetNextLogin">
  <PersistedClaims>
    <PersistedClaim ClaimTypeReferenceId="newPassword" PartnerClaimType="passwordProfile.password" />
    <!-- 去掉AlwaysUseDefaultValue,确保正确重置标志 -->
    <PersistedClaim ClaimTypeReferenceId="forceChangePasswordNextSignIn" PartnerClaimType="passwordProfile.forceChangePasswordNextSignIn" DefaultValue="false" />
  </PersistedClaims>
  <IncludeTechnicalProfile ReferenceId="AAD-UserWritePasswordUsingObjectId" />
</TechnicalProfile>

4. 确保改密页面TechnicalProfile存在

如果策略中没有SelfAsserted-ForcePasswordReset,添加以下配置:

<TechnicalProfile Id="SelfAsserted-ForcePasswordReset">
  <DisplayName>Force Password Reset</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  <Metadata>
    <Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
    <Item Key="language.button_continue">Continue</Item>
  </Metadata>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="objectId" />
    <InputClaim ClaimTypeReferenceId="signInNames.emailAddress" />
  </InputClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="newPassword" Required="true" />
    <OutputClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
  </OutputClaims>
  <ValidationTechnicalProfiles>
    <ValidationTechnicalProfile ReferenceId="AAD-UserWritePasswordUsingObjectId-ResetNextLogin" />
  </ValidationTechnicalProfiles>
</TechnicalProfile>

额外验证步骤

  1. 在Azure门户中检查目标用户的属性,确认passwordProfile.forceChangePasswordNextSignIn确实为true
  2. 测试时使用全新用户,避免缓存影响
  3. 启用策略日志,跟踪forceChangePasswordNextSignIn Claim的传递与判断过程

内容的提问来源于stack exchange,提问作者Ahtesham Shah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 19:07:16