ClaimsTransformationsClaimsTransformations

备注

在 Azure Active Directory B2C 中,custom policies 主要用于解决复杂方案。In Azure Active Directory B2C, custom policies are designed primarily to address complex scenarios. 大多数情况下,建议使用内置的用户流For most scenarios, we recommend that you use built-in user flows.

ClaimsTransformations 元素包含一个可在用户旅程中用作自定义策略的一部分的声明转换函数列表。The ClaimsTransformations element contains a list of claims transformation functions that can be used in user journeys as part of a custom policy. 声明转换可以将给定声明转换为另一个声明。A claims transformation converts a given claim into another one. 在声明转换中,指定转换方法,例如将项添加到一个字符串集合或更改字符串的大小写。In the claims transformation, you specify the transform method, for example adding an item to a string collection or changing the case of a string.

若要包含可在用户旅程中使用的声明转换函数的列表,必须在策略的 BuildingBlocks 部分下声明 ClaimsTransformations XML 元素。To include the list of claims transformation functions that can be used in the user journeys, a ClaimsTransformations XML element must be declared under the BuildingBlocks section of the policy.

<ClaimsTransformations>
  <ClaimsTransformation Id="<identifier>" TransformationMethod="<method>">
    ...
  </ClaimsTransformation>
</ClaimsTransformations>

ClaimsTransformation 元素包含以下属性:The ClaimsTransformation element contains the following attributes:

属性Attribute 必须Required 说明Description
IDId Yes 用于唯一标识声明转换的标识符。An identifier that is used to uniquely identify the claim transformation. 从策略中的其他 XML 元素引用此标识符。The identifier is referenced from other XML elements in the policy.
TransformationMethodTransformationMethod Yes 用于声明转换的转换方法。The transform method to use in the claims transformation. 每个声明转换都有其自己的值。Each claim transformation has its own values. 有关可用值的完整列表,请参阅声明转换引用See the claims transformation reference for a complete list of the available values.

ClaimsTransformationClaimsTransformation

ClaimsTransformation 元素包含以下元素:The ClaimsTransformation element contains the following elements:

<ClaimsTransformation Id="<identifier>" TransformationMethod="<method>">
  <InputClaims>
    ...
  </InputClaims>
  <InputParameters>
    ...
  </InputParameters>
  <OutputClaims>
    ...
  </OutputClaims>
</ClaimsTransformation>
元素Element 出现次数Occurrences 说明Description
InputClaimsInputClaims 0:10:1 InputClaim 元素列表,这些元素用于指定被看作声明转换输入的声明类型。A list of InputClaim elements that specify claim types that are taken as input to the claims transformation. 每个元素都包含对在策略的 ClaimsSchema 部分定义的 ClaimType 的引用。Each of these elements contains a reference to a ClaimType already defined in the ClaimsSchema section in the policy.
InputParametersInputParameters 0:10:1 InputParameter 元素列表,这些元素作为声明转换输入提供。A list of InputParameter elements that are provided as input to the claims transformation.
OutputClaimsOutputClaims 0:10:1 OutputClaim 元素列表,这些元素用于指定在调用 ClaimsTransformation 后生成的声明类型。A list of OutputClaim elements that specify claim types that are produced after the ClaimsTransformation has been invoked. 每个元素都包含对在 ClaimsSchema 部分定义的 ClaimType 的引用。Each of these elements contains reference to a ClaimType already defined in the ClaimsSchema section.

InputClaimsInputClaims

InputClaims 元素包含以下元素:The InputClaims element contains the following element:

元素Element 出现次数Occurrences 说明Description
InputClaimInputClaim 1:n1:n 预期的输入声明类型。An expected input claim type.

InputClaimInputClaim

InputClaim 元素包含以下属性:The InputClaim element contains the following attributes:

属性Attribute 必须Required 说明Description
ClaimTypeReferenceIdClaimTypeReferenceId Yes 对在策略的 ClaimsSchema 部分定义的 ClaimType 的引用。A reference to a ClaimType already defined in the ClaimsSchema section in the policy.
TransformationClaimTypeTransformationClaimType Yes 用于引用转换声明类型的标识符。An identifier to reference a transformation claim type. 每个声明转换都有其自己的值。Each claim transformation has its own values. 有关可用值的完整列表,请参阅声明转换引用See the claims transformation reference for a complete list of the available values.

InputParametersInputParameters

InputParameters 元素包含以下元素:The InputParameters element contains the following element:

元素Element 出现次数Occurrences 说明Description
InputParameterInputParameter 1:n1:n 预期的输入参数。An expected input parameter.

InputParameterInputParameter

属性Attribute 必须Required 说明Description
IDId Yes 是对声明转换方法的参数的引用的标识符。An identifier that is a reference to a parameter of the claims transformation method. 每个声明转换方法都有其自己的值。Each claims transformation method has its own values. 有关可用值的完整列表,请参阅声明转换表。See the claims transformation table for a complete list of the available values.
数据类型DataType Yes 参数的数据类型,例如根据自定义策略 XML 架构中的 DataType 枚举的字符串、布尔值、Int 或 DateTime。The type of data of the parameter, such as String, Boolean, Int, or DateTime as per the DataType enumeration in the custom policy XML schema. 此类型用于正确执行算术操作。This type is used to perform arithmetic operations correctly. 每个声明转换都有其自己的值。Each claim transformation has its own values. 有关可用值的完整列表,请参阅声明转换引用See the claims transformation reference for a complete list of the available values.
ValueValue Yes 将逐字字符串传递到传递的一个值。A value that is passed verbatim to the transformation. 某些值是任意的,某些值是从声明转换方法中选择的。Some of the values are arbitrary, some of them you select from the claims transformation method.

OutputClaimsOutputClaims

OutputClaims 元素包含以下元素:The OutputClaims element contains the following element:

元素Element 出现次数Occurrences 说明Description
OutputClaimOutputClaim 0:n0:n 预期的输出声明类型。An expected output claim type.

OutputClaimOutputClaim

OutputClaim 元素包含以下属性:The OutputClaim element contains the following attributes:

属性Attribute 必须Required 说明Description
ClaimTypeReferenceIdClaimTypeReferenceId Yes 对在策略的 ClaimsSchema 部分定义的 ClaimType 的引用。A reference to a ClaimType already defined in the ClaimsSchema section in the policy.
TransformationClaimTypeTransformationClaimType Yes 用于引用转换声明类型的标识符。An identifier to reference a transformation claim type. 每个声明转换都有其自己的值。Each claim transformation has its own values. 有关可用值的完整列表,请参阅声明转换引用See the claims transformation reference for a complete list of the available values.

如果输入声明和输出声明具有相同的类型(字符串或布尔值),可以将相同的输入声明用作输出声明。If input claim and the output claim are the same type (string, or boolean), you can use the same input claim as the output claim. 在这种情况下,声明转换更改具有输出值的输入声明。In this case, the claims transformation changes the input claim with the output value.

示例Example

例如,可能会存储用户接受的上一版本的服务条款。For example, you may store the last version of your terms of services that the user accepted. 更新服务条款时,可以请求用户接受新版本。When you update the terms of services, you can ask the user to accept the new version. 在以下示例中,HasTOSVersionChanged 声明将 TOSVersion 声明的值与 LastTOSAcceptedVersion 声明的值进行比较,然后返回布尔 TOSVersionChanged 声明。In the following example, the HasTOSVersionChanged claims transformation compares the value of the TOSVersion claim with the value of the LastTOSAcceptedVersion claim and then returns the boolean TOSVersionChanged claim.

<BuildingBlocks>
  <ClaimsSchema>
    <ClaimType Id="TOSVersionChanged">
      <DisplayName>Indicates if the TOS version accepted by the end user is equal to the current version</DisplayName>
      <DataType>boolean</DataType>
    </ClaimType>
    <ClaimType Id="TOSVersion">
      <DisplayName>TOS version</DisplayName>
      <DataType>string</DataType>
    </ClaimType>
    <ClaimType Id="LastTOSAcceptedVersion">
      <DisplayName>TOS version accepted by the end user</DisplayName>
      <DataType>string</DataType>
    </ClaimType>
  </ClaimsSchema>

  <ClaimsTransformations>
    <ClaimsTransformation Id="HasTOSVersionChanged" TransformationMethod="CompareClaims">
      <InputClaims>
        <InputClaim ClaimTypeReferenceId="TOSVersion" TransformationClaimType="inputClaim1" />
        <InputClaim ClaimTypeReferenceId="LastTOSAcceptedVersion" TransformationClaimType="inputClaim2" />
      </InputClaims>
      <InputParameters>
        <InputParameter Id="operator" DataType="string" Value="NOT EQUAL" />
      </InputParameters>
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="TOSVersionChanged" TransformationClaimType="outputClaim" />
      </OutputClaims>
    </ClaimsTransformation>
  </ClaimsTransformations>
</BuildingBlocks>

声明转换引用Claims transformations reference

有关声明转换的示例,请参阅以下引用页:For examples of claims transformations, see the following reference pages: