在Custom Police Azure ADB2C中本地化API响应

问题描述

我已经在Azure ADB2C自定义策略中实现了本地化。

<ClaimType Id="signInName">
    <displayName>Please enter your email</displayName>
    <DataType>string</DataType>
    <UserHelpText>Enter your email address to signin</UserHelpText>
    <Restriction>
        <Pattern RegularExpression="^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"/>
    </Restriction>
</ClaimType>

<Localization Enabled="true">
    <SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll">
        <SupportedLanguage>en</SupportedLanguage>
        <SupportedLanguage>es</SupportedLanguage>
    </SupportedLanguages>
    <LocalizedResources Id="en">
        <LocalizedStrings>
            <LocalizedString ElementType="ClaimType" ElementId="signInName" StringId="displayName">Please enter your email</LocalizedString>
            <LocalizedString ElementType="ClaimType" ElementId="signInName" StringId="UserHelpText">Enter your email address to signin</LocalizedString>
        </LocalizedStrings>
    </LocalizedResources>
    <LocalizedResources Id="es">
        <LocalizedStrings>
            <LocalizedString ElementType="ClaimType" ElementId="signInName" StringId="displayName">Por favor introduzca su correo electrónico</LocalizedString>
            <LocalizedString ElementType="ClaimType" ElementId="signInName" StringId="UserHelpText">Ingrese su dirección de correo electrónico para iniciar sesión</LocalizedString>
        </LocalizedStrings>
    </LocalizedResources>
</Localization>

一切正常,但是单击登录按钮时,将进行API调用,并且响应始终为英语。同样,用于指示语言未在API调用中发送的查询字符串参数。任何帮助将不胜感激。

enter image description here

解决方法

您需要首先找到显示此错误的字符串ID。

我们支持these用于本地化的ID,您可能已在策略中对其进行了自定义。

然后,一旦知道错误消息使用了哪个ID,就可以添加如下所示的LocalizedString元素(例如,假设ElementTypeErrorMessageStringIDDefaultMessage):

<LocalizedString ElementType="ErrorMessage" StringId="DefaultMessage">#Invalid username or password.</LocalizedString>

您可以在此处找到相同的不同示例:https://docs.microsoft.com/en-us/azure/active-directory-b2c/custom-policy-localization