首页 > 解决方案 > Azure AD B2C 自定义策略 - 仅使用 String.Format 删除连字符

问题描述

在 Azure B2C 自定义策略中,我想从 objectId(GUID) 声明类型中删除连字符“-”并将其分配给另一个声明类型。

例如:

输入:e8023a66-30ed-4e31-a17e-c013081704a0 输出:e8023a6630ed4e31a17ec013081704a0

我目前尝试了以下方法:

<InputParameter Id="stringFormat" DataType="string" Value="00000000000000000000000000000000,{0}" />
<InputParameter Id="stringFormat" DataType="string" Value="{0:################################}" />
<InputParameter Id="stringFormat" DataType="string" Value="{0:#}" /> 

我在 ClaimsTransformation 中使用 FormatStringClaim 转换方法来实现相同的目的,但是该值被分配给带有连字符的目标声明类型。

你能帮我删除连字符吗?

注意:我不能使用任何其他字符串操作,如替换或拆分,因为 Azure AD 仅支持 String.Format 方法。

标签: azureazure-active-directoryazure-ad-b2c

解决方案


I am using FormatStringClaim transformationmethod in ClaimsTransformation to achieve the same however the value is getting assigned to the target claimtype with hyphen.

It sounds like you incorrectly configured your Claims Transformation and have assigned your original GUID as both your input and output claims. You need to update the ClaimTypeReferenceId with the claim you want to store your modified GUID in.

Example:

<ClaimsTransformation Id="RemoveHash" TransformationMethod="FormatStringClaim">
    <InputClaims>
        <InputClaim ClaimTypeReferenceId="originalGuid" TransformationClaimType="inputClaim" />
    </InputClaims>
    <InputParameters>
        <InputParameter Id="stringFormat" DataType="string" Value="{0}" />
    </InputParameters>
    <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="modifiedGuid" TransformationClaimType="outputClaim" />
    </OutputClaims>
</ClaimsTransformation>

推荐阅读