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

Azure B2C Format Localized String功能失效问题求助

Azure AD B2C 忘记密码流程本地化字符串格式化不生效问题修复

问题说明

在Azure AD B2C忘记密码用户流中,尝试将用户givenName声明嵌入本地化字符串,按配置后始终显示默认值,未实现动态替换。操作页面为自断言页面,现有配置如下:

现有自断言页面TechnicalProfile配置

<TechnicalProfile Id="Select-Method-Email">
  <DisplayName>Allow user to choose their MFA Method</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.radiobutton</Item>
  </Metadata>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="givenName" />
  </InputClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="ForgotPasswordOptionsEmail" Required="true" />
  </OutputClaims>
</TechnicalProfile>

现有本地化字符串配置

<LocalizedResources Id="api.selfasserted.radiobutton.en">
  <LocalizedStrings>
    <LocalizedString ElementType="UxElement" StringId="heading"></LocalizedString>
    <LocalizedString ElementType="FormatLocalizedStringTransformationClaimType" StringId="initial_intro">Welcome Back, {0} </LocalizedString>
    <LocalizedString ElementType="UxElement" StringId="button_continue">Next</LocalizedString>
    <LocalizedString ElementType="UxElement" StringId="button_cancel">Start Over</LocalizedString>
  </LocalizedStrings>
</LocalizedResources>

现有声明转换配置

<ClaimsTransformation Id="CopyNameToReadOnly" TransformationMethod="FormatLocalizedString">
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="givenName" />
  </InputClaims>
  <InputParameters>
    <InputParameter Id="stringFormatId" DataType="string" Value="initial_intro" />
  </InputParameters>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="readOnlyName" TransformationClaimType="outputClaim" />
  </OutputClaims>
</ClaimsTransformation>

修复步骤

1. 在TechnicalProfile中触发声明转换

声明转换未被执行是核心问题,需在Select-Method-Email中添加输入声明转换节点,并传入转换后的声明:

<TechnicalProfile Id="Select-Method-Email">
  <DisplayName>Allow user to choose their MFA Method</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.radiobutton</Item>
  </Metadata>
  <!-- 添加此节点执行声明转换 -->
  <InputClaimsTransformations>
    <InputClaimsTransformation ReferenceId="CopyNameToReadOnly" />
  </InputClaimsTransformations>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="givenName" />
    <!-- 传入转换后的声明 -->
    <InputClaim ClaimTypeReferenceId="readOnlyName" />
  </InputClaims>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="ForgotPasswordOptionsEmail" Required="true" />
  </OutputClaims>
</TechnicalProfile>

2. 定义readOnlyName声明类型

需在ClaimTypes节点中添加该声明的定义,确保页面可以正确渲染:

<ClaimType Id="readOnlyName">
  <DisplayName>Welcome Message</DisplayName>
  <DataType>string</DataType>
  <UserHelpText></UserHelpText>
  <!-- 使用Paragraph类型确保文本直接显示,无需用户输入 -->
  <UserInputType>Paragraph</UserInputType>
</ClaimType>

3. 验证声明传递链路

确保进入Select-Method-Email页面之前,givenName声明已被正确获取(例如通过读取用户目录信息的TechnicalProfile),只有当该声明存在时,格式化才能生效。

4. 确认本地化资源匹配

检查LocalizedResources的IDapi.selfasserted.radiobutton.en与ContentDefinition的ID完全匹配,且stringFormatId的值initial_intro与本地化字符串的StringId一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 05:37:06