将包含 True 或 False 的 SAML 属性映射到布尔数据类型的声明

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

我正在尝试定义一个属性,该属性将由 SAML 2.0 身份提供商返回到 AAD B2C 并在自定义策略中进行处理。

目标是 SAML 属性定义布尔值,并且 AAD B2C 能够根据声明的值执行逻辑。

SAML 属性代表 True 或 False,如下所示:

<saml:Attribute Name="http://schemas.custom/claim/booleanexample" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
    <saml:AttributeValue>True</saml:AttributeValue>
</saml:Attribute>

尝试将此 SAML 属性映射到自定义策略

ClaimsSchema
中定义的数据类型为
boolean
的声明时,会引发错误。

App Insights 中的消息:

ID 为“http://schemas.custom/claim/booleanexample”的声明的数据类型“String”与策略中指定的 ID 为“BooleanExample”的claimType 的数据类型“Boolean”不匹配。

<ClaimType Id="BooleanExample">
  <DataType>boolean</DataType>
</ClaimType>

我看不到任何在 SAML 中显式定义属性类型的机制(看来 AttributeValue 应该是 xs:any 类型)。

我尝试传递常用值,包括 0/1、True/False、true/false,但没有成功。

是否真的需要使用字符串声明来处理此问题,然后使用声明转换填充布尔声明?

azure-ad-b2c saml-2.0 azure-ad-b2c-custom-policy claims
1个回答
1
投票

看来声明必须映射为字符串,并使用 CompareClaimToValue 声明转换进行检查,该转换使用比较结果设置布尔声明。

<ClaimsTransformation Id="CreateBooleanClaimFromString" TransformationMethod="CompareClaimToValue">
    <InputClaims>
      <InputClaim ClaimTypeReferenceId="samlBooleanClaimAsString" TransformationClaimType="inputClaim1" />
    </InputClaims>
    <InputParameters>
      <InputParameter Id="compareTo" DataType="string" Value="true" />
      <InputParameter Id="operator" DataType="string" Value="equal" />
      <InputParameter Id="ignoreCase" DataType="string" Value="false" />
    </InputParameters>
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="samlBooleanClaimAsBoolean" TransformationClaimType="outputClaim" />
    </OutputClaims>
</ClaimsTransformation>
© www.soinside.com 2019 - 2024. All rights reserved.