自定义政策 - REST 技术配置文件中的本地化声明

问题描述 投票:0回答:2

我需要在自定义策略的

RESTful 提供商 
技术配置文件(不在自断言技术配置文件中)中传递带有本地化 DefaultValue 的输入声明,但一旦我添加对转换方法的引用
GetLocalizedStringsTransformation 
InputClaimsTransformations
内我的应用程序崩溃了。

本地化输入声明必须位于RESTful提供商技术配置文件内。

自定义声明定义

<ClaimsSchema>
    <ClaimType Id="localizedResult">
        <DataType>string</DataType>
        <UserInputType>Readonly</UserInputType>
    </ClaimType>
</ClaimsSchema>

本地化

<Localization Enabled="true">
    <SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll">
      <SupportedLanguage>en</SupportedLanguage>
      <SupportedLanguage>es</SupportedLanguage>
    </SupportedLanguages>
    <LocalizedResources Id="api.selfasserted.en">
      <LocalizedStrings>
        <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="localized_string">English Value</LocalizedString>
      </LocalizedStrings>
    </LocalizedResources>
    <LocalizedResources Id="api.selfasserted.es">
      <LocalizedStrings>
        <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="localized_string">Valor en Espanol</LocalizedString>
      </LocalizedStrings>
    </LocalizedResources>
</Localization>

索赔转型

<ClaimsTransformations>
    <ClaimsTransformation Id="GetLocalizedStringsForCustomClaim" TransformationMethod="GetLocalizedStringsTransformation">
        <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="localizedResult" TransformationClaimType="localized_string" />
        </OutputClaims>
    </ClaimsTransformation>
</ClaimsTransformations>

RESTful 提供商技术简介:

<TechnicalProfile Id="REST-Technical-Profile">
    <DisplayName>My App</DisplayName>
    <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    <Metadata>
        <Item Key="IncludeClaimResolvingInClaimsHandling">true</Item>
        <Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
        <Item Key="ServiceUrl">https://my-app.test/api/endpoint</Item>
        <Item Key="SendClaimsIn">Body</Item>
        <Item Key="AuthenticationType">Bearer</Item>
    </Metadata>
    <InputClaimsTransformations>
        <InputClaimsTransformation ReferenceId="GetLocalizedStringsForCustomClaim" />
    </InputClaimsTransformations>
    <InputClaims>
        <InputClaim ClaimTypeReferenceId="myCustomClaim" DefaultValue="{Claim:localizedResult}" AlwaysUseDefaultValue="true" />
    </InputClaims>
</TechnicalProfile>

我尝试使用方法

CreateStringClaim
,它按预期创建了一个转换值,但该方法不允许我根据语言和自定义翻译集合映射翻译。

azure-ad-b2c-custom-policy azure-ad-b2c
2个回答
0
投票

我认为您需要元数据设置来启用声明解析器。 文档:https://learn.microsoft.com/en-us/azure/active-directory-b2c/claim-resolver-overview#using-claim-resolvers

<Metadata>
    <Item Key="IncludeClaimResolvingInClaimsHandling">true</Item>
</Metadata>

根据文档,您需要此设置并使用 AlwaysUseDefaultValue=true 来实现 RESTful 配置文件。


-2
投票

您可以探索使用 JWT 令牌将输入传递到您的策略的方法。这里有一篇很好的文章可供参考:pass-inputs-to-b2c-custom-policy

© www.soinside.com 2019 - 2024. All rights reserved.