【问题标题】:How to use a claim resolver in Persisted claims?如何在持久声明中使用声明解析器?
【发布时间】:2020-08-05 02:51:55
【问题描述】:

每当用户登录时,我想将上次登录时间存储在扩展字段中。我创建了如下所示的技术配置文件,并从编排步骤中调用它。我的问题是它没有解决{Context:DateTimeInUtc},而是将单词{Context:DateTimeInUtc} 写入属性。

    <TechnicalProfile Id="Custom-TP-AAD-UpdateLastLoginDate-UsingObjectId">
     <Metadata>
      <Item Key="Operation">Write</Item>
      <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>
     </Metadata>
     <IncludeInSso>false</IncludeInSso>
     <InputClaims>
      <InputClaim ClaimTypeReferenceId="objectId" Required="true" />
     </InputClaims>
     <PersistedClaims>
      <PersistedClaim ClaimTypeReferenceId="objectId" />
      <PersistedClaim ClaimTypeReferenceId="extension_LastLoginDate" PartnerClaimType="{Context:DateTimeInUtc}" />
     </PersistedClaims>
     <IncludeTechnicalProfile ReferenceId="AAD-Common" />
    </TechnicalProfile>

我做错了什么?

【问题讨论】:

  • 应该是DefaultValue="{Context:CorrelationId}" 而不是PartnerClaimType="{Context:DateTimeInUtc}"
  • 如果添加&lt;Item Key="IncludeClaimResolvingInClaimsHandling"&gt;true&lt;/Item&gt;会怎样?
  • 我已经尝试过使用 DefaultValue 但它不起作用,之后只有我在 SO 中发布了这个问题。
  • 我也试过 true 但它没有解决索赔。
  • 嗨,克里斯 - 有没有想过使用声明转换来完成这项工作,或者可能正在使用 rest api 技术配置文件?

标签: azure-ad-b2c claims resolver


【解决方案1】:

我终于能够使用声明转换来做到这一点。
根据 Microsoft 声明解析器目前不能与持久声明一起使用。他们正在努力为更多技术配置文件类型启用此功能。

以下是执行此操作的详细步骤。

第 1 步:首先添加两个声明

    <ClaimType Id="extension_LastLoginDate">
        <DisplayName>last time user logged in</DisplayName>
        <DataType>dateTime</DataType>
        <UserHelpText>last time user logged in</UserHelpText>
      </ClaimType>
      <ClaimType Id="CurrentTime">
        <DisplayName>Current time</DisplayName>
        <DataType>dateTime</DataType>
        <UserHelpText>Current time</UserHelpText>
      </ClaimType>

第一个是扩展属性,用于将值存储在 AD 中。第二个是保存当前日期时间的临时变量。

第 2 步:添加新的声明转换,这是在 CurrentTime 声明中获取当前数据时间 (utc) 所必需的


      <ClaimsTransformation Id="GetSystemDateTime" TransformationMethod="GetCurrentDateTime">
        <OutputClaims>
          <OutputClaim ClaimTypeReferenceId="CurrentTime" TransformationClaimType="currentDateTime" />
        </OutputClaims>
      </ClaimsTransformation>

第 3 步:定义技术配置文件以更新 extension_LastLoginDate 属性

        <TechnicalProfile Id="Custom-TP-AAD-WriteLastLoginDateUsingObjectId">
          <Metadata>
            <Item Key="Operation">Write</Item>
            <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>
          </Metadata>
          <IncludeInSso>false</IncludeInSso>
          <InputClaims>
            <InputClaim ClaimTypeReferenceId="objectId" Required="true" />
          </InputClaims>
          <PersistedClaims>
            <PersistedClaim ClaimTypeReferenceId="objectId" />
            <PersistedClaim ClaimTypeReferenceId="CurrentTime" PartnerClaimType="extension_LastLoginDate" />
          </PersistedClaims>
          <IncludeTechnicalProfile ReferenceId="AAD-Common" />
        </TechnicalProfile>

第 4 步:更新现有技术资料 AAD-UserReadUsingObjectId。这是一个重要的步骤,您将调用索赔转换并将CurrentTime 索赔添加到索赔包中。我使用了AAD-UserReadUsingObjectId 技术配置文件,但它可以是任何其他技术配置文件,只要确保已调用索赔转换并将CurrentTime 索赔添加到索赔包。

        <TechnicalProfile Id="AAD-UserReadUsingObjectId">
          <Metadata>
            <Item Key="Operation">Read</Item>
            <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">true</Item>
          </Metadata>
          <IncludeInSso>false</IncludeInSso>
          <InputClaims>
            <InputClaim ClaimTypeReferenceId="objectId" Required="true" />
          </InputClaims>
          <OutputClaims>
            <OutputClaim ClaimTypeReferenceId="signInNames.emailAddress" />
            <OutputClaim ClaimTypeReferenceId="displayName" />
            <OutputClaim ClaimTypeReferenceId="objectId" />
            <OutputClaim ClaimTypeReferenceId="CurrentTime" />
          </OutputClaims>
          <OutputClaimsTransformations>
            <OutputClaimsTransformation ReferenceId="GetSystemDateTime" />
          </OutputClaimsTransformations>
          <IncludeTechnicalProfile ReferenceId="AAD-Common" />
        </TechnicalProfile>

第 5 步:最后,您可以在任何用户旅程中从 OrchestrationStep 之一调用 Custom-TP-AAD-WriteLastLoginDateUsingObjectIdtechnical 配置文件

        <OrchestrationStep Order="5" Type="ClaimsExchange">
          <ClaimsExchanges>
            <ClaimsExchange Id="WriteLastLogonTime" TechnicalProfileReferenceId="Custom-TP-AAD-WriteLastLoginDateUsingObjectId" />
          </ClaimsExchanges>
        </OrchestrationStep>

【讨论】:

    猜你喜欢
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2018-07-02
    • 1970-01-01
    • 2019-01-20
    • 2018-07-24
    • 2011-02-08
    相关资源
    最近更新 更多