How to add a single backslash via transformation in a B2C custom policy?

Gola, Mariusz 45 Reputation points
2023-07-06T12:48:04.4066667+00:00

Hi,

Have a requirement to prepend a claim with a AD\ in a B2C custom policy, I'm having trouble adding a single backslash. When I add '\AD' it transforms to '\\AD' . When I add '\', it transforms to '\\AD', etc.... So basically it always doubles the backslashes.

Below is the transformation. Please advise. Thank you.

    <ClaimsTransformation Id="PrependAD" TransformationMethod="FormatStringClaim">
        <InputClaims>
          <InputClaim ClaimTypeReferenceId="extension_signinName"
            TransformationClaimType="inputClaim" />
        </InputClaims>
        <InputParameters>
          <InputParameter Id="stringFormat" DataType="string"
            Value="AD\{0}" />
        </InputParameters>
        <OutputClaims>
          <OutputClaim ClaimTypeReferenceId="extension_signinName"
            TransformationClaimType="outputClaim" />
        </OutputClaims>
      </ClaimsTransformation>
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. James Hamil 27,216 Reputation points Microsoft Employee Moderator
    2023-07-07T19:37:26.6066667+00:00

    Hi @Gola, Mariusz , you can use &#92 as a character entity reference for XML. This will represent the backslash. For example:

    <ClaimsTransformation Id="PrependAD" TransformationMethod="FormatStringClaim">
        <InputClaims>
            <InputClaim ClaimTypeReferenceId="extension_signinName" TransformationClaimType="inputClaim" />
        </InputClaims>
        <InputParameters>
            <InputParameter Id="stringFormat" DataType="string" Value="AD&#92;{0}" />
        </InputParameters>
        <OutputClaims>
            <OutputClaim ClaimTypeReferenceId="extension_signinName" TransformationClaimType="outputClaim" />
        </OutputClaims>
    </ClaimsTransformation>
    

    Please let me know if you have any questions and I can help you further.

    If this answer helps you please mark "Accept Answer" so other users can reference it.

    Thank you,

    James


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.