自定义策略:即使语言直接传递给用户流,也能阻止不支持的语言环境

Custom Policies: Prevent unsupported locales even if language is passed directly to the user flow

我们已经开始使用一些自定义的本地化 html 文件来向我们的用户显示一些本地化的标题等。

根据 this article,我们刚刚上传了几个 html 文件用于渲染。

https://contoso.blob.core.windows.net/{Culture:LanguageName}/myHTML/unified.html

但是,当用户流程以明确的语言环境集(例如 &lang=esUI-locales=es-ES)启动时,我们 没有该语言环境的文件,我们得到一个错误页面。

AADB2C90002: The CORS resource 'https://anyhelpappreciated.blob.core.windows.net/es/myHTML/unified.html' returned a 404 not found.

我们已经设置了 SupportedLanguages,但如果显式传递语言环境,这似乎没有任何作用。我不想依赖不向我传递此参数的应用程序。

    <Localization Enabled="true">
      <SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll">
        <SupportedLanguage>en</SupportedLanguage>
        <SupportedLanguage>de</SupportedLanguage>
        <SupportedLanguage>it</SupportedLanguage>
      </SupportedLanguages>
...

有什么办法可以避免这种情况吗?

此行为是 "by design",无法更改。

https://github.com/MicrosoftDocs/azure-docs/issues/47654

For localization, you can provide the query string parameter, ui_locales, from your application. When you call into Azure AD B2C, your page is translated to the locale that you have indicated. This type of configuration gives you complete control over the languages in your user flow and ignores the language settings of the customer's browser. You might not need that level of control over what languages your customer sees. If you don't provide a ui_locales parameter, the customer's experience is dictated by their browser's settings. You can still control which languages your user flow is translated to by adding it as a supported language. If a customer's browser is set to show a language that you don't want to support, then the language that you selected as a default in supported cultures is shown instead.

The {Culture:RFC5646} claim resolver works in the same way. Meaning If a customer's browser is set to show a language that you don't want to support, then the language that you selected as a default in supported cultures is sent to the HTML page instead.

The only case where an unsupported ui_locales will be sent to the HTML page, is when the app passes the missing ui_locales in the query string. In this case we consider that to be an application decision and allow it to override supported cultures configuration.

So, make sure your application sends only supported language in the ui_locales query string parameter.