0

I did localisation in my custom policy, but in certain steps I'm calling REST API to validate some data. Response is coming in English, but now I need to translate that messages too as a part of localisation. Is there any way to do this in B2C?

Here is the response I'm getting from API:

{
    "userMessage": "Password is incorrect",
    "version":"1.0.0",
    "status": 409,
    "code": "API12345",
    "requestId":"50f0bd91-2ff4-4b8f-828f-00f170519ddb",
    "developerMessage":"Verbose description of problem and how to fix it.",
    "moreInfo": "https://restapi/error/API12345/moreinfo"
}
Alex AIT
  • 17,361
  • 3
  • 36
  • 73
Alex
  • 734
  • 6
  • 29

1 Answers1

1

You can send the localisation parameter to the REST API and have it return a localised error. Or you can return back an error code from the API instead of an error string. Then use the following example to have this done in policy:

    <BuildingBlocks>
        <ClaimsSchema>
            <ClaimType Id="errorCode">
                <DisplayName>errorCode</DisplayName>
                <DataType>string</DataType>
                <UserHelpText>A claim responsible for holding response codes to send to the relying party</UserHelpText>
            </ClaimType>
            <ClaimType Id="messageValue">
                <DisplayName>Message</DisplayName>
                <DataType>string</DataType>
                <UserHelpText>A claim responsible for holding response messages to send to the relying party</UserHelpText>
                <UserInputType>Paragraph</UserInputType>
                <Restriction>
                    <Enumeration Text="errorCode1" Value="will get overidden by localization" />
                    <Enumeration Text="errorCode2" Value="will get overidden by localization" />
                </Restriction>
            </ClaimType>
        </ClaimsSchema>
        <ClaimsTransformations>
            <ClaimsTransformation Id="SetMessageId" TransformationMethod="CreateStringClaim">
                <InputParameters>
                    <InputParameter Id="value" DataType="string" Value="errorCode1" /> <!-- Toggle for errorCode2 -->
                </InputParameters>
                <OutputClaims>
                    <OutputClaim ClaimTypeReferenceId="errorCode" TransformationClaimType="createdClaim" />
                </OutputClaims>
            </ClaimsTransformation>
            <ClaimsTransformation Id="GetLocalizedMessage" TransformationMethod="GetMappedValueFromLocalizedCollection">
                <InputClaims>
                    <InputClaim ClaimTypeReferenceId="errorCode" TransformationClaimType="mapFromClaim" />
                </InputClaims>
                <OutputClaims>
                    <OutputClaim ClaimTypeReferenceId="messageValue" TransformationClaimType="restrictionValueClaim" />
                </OutputClaims>
            </ClaimsTransformation>
        </ClaimsTransformations>
        <ContentDefinitions>
            <ContentDefinition Id="api.selfasserted">
                <LocalizedResourcesReferences MergeBehavior="Prepend">
                    <LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.selfasserted.en" />
                    <LocalizedResourcesReference Language="es" LocalizedResourcesReferenceId="api.selfasserted.es" />
                </LocalizedResourcesReferences>
            </ContentDefinition>
        </ContentDefinitions>
        <Localization Enabled="true">
            <SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll">
                <SupportedLanguage>en</SupportedLanguage>
                <SupportedLanguage>es</SupportedLanguage>
            </SupportedLanguages>
            <LocalizedResources Id="api.selfasserted.en">
                <LocalizedCollections>
                    <LocalizedCollection ElementType="ClaimType" ElementId="messageValue" TargetCollection="Restriction">
                        <Item Text="errorCode1" Value="First message in english" />
                        <Item Text="errorCode2" Value="Second message in english" />
                    </LocalizedCollection>
                </LocalizedCollections>
            </LocalizedResources>
            <LocalizedResources Id="api.selfasserted.es">
                <LocalizedCollections>
                    <LocalizedCollection ElementType="ClaimType" ElementId="messageValue" TargetCollection="Restriction">
                        <Item Text="errorCode1" Value="Primer mensaje en español" />
                        <Item Text="errorCode2" Value="Segundo mensaje en español" />
                    </LocalizedCollection>
                </LocalizedCollections>
            </LocalizedResources>
        </Localization>
    </BuildingBlocks>
    <ClaimsProviders>
        <ClaimsProvider>
            <DisplayName>Self Asserted</DisplayName>
            <TechnicalProfiles>
                <TechnicalProfile Id="SelfAsserted-WelcomePage">
                    <DisplayName>User profile</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>
                    </Metadata>
                    <InputClaimsTransformations>
                        <InputClaimsTransformation ReferenceId="SetMessageId" />
                        <InputClaimsTransformation ReferenceId="GetLocalizedMessage" />
                    </InputClaimsTransformations>
                    <InputClaims>
                        <InputClaim ClaimTypeReferenceId="messageValue" />
                    </InputClaims>
                    <OutputClaims>
                        <OutputClaim ClaimTypeReferenceId="email"/>
                        <OutputClaim ClaimTypeReferenceId="messageValue"/>
                    </OutputClaims>
                </TechnicalProfile>
            </TechnicalProfiles>
        </ClaimsProvider>
    </ClaimsProviders>
    <UserJourneys>
        <UserJourney Id="Localization_Tester">
            <OrchestrationSteps>
                <OrchestrationStep Order="1" Type="ClaimsExchange">
                    <ClaimsExchanges>
                        <ClaimsExchange Id="SelfAsserted-WelcomePage" TechnicalProfileReferenceId="SelfAsserted-WelcomePage" />
                    </ClaimsExchanges>
                </OrchestrationStep>
                <OrchestrationStep Order="2" Type="ClaimsExchange">
                    <ClaimsExchanges>
                        <ClaimsExchange Id="AAD-UserReadUsingEmailAddress" TechnicalProfileReferenceId="AAD-UserReadUsingEmailAddress" />
                    </ClaimsExchanges>
                </OrchestrationStep>
                <OrchestrationStep Order="3" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="JwtIssuer" />
            </OrchestrationSteps>
        </UserJourney>
    </UserJourneys>
Alex AIT
  • 17,361
  • 3
  • 36
  • 73
Jas Suri - MSFT
  • 10,605
  • 2
  • 10
  • 20
  • Thanks, decided to use and "claim resolvers" and API will send back the translated messages. – Alex Jan 21 '20 at 15:57