Azure B2C:在何处创建要在自定义策略中使用的日期时间扩展属性 - 门户或自定义策略或两者?

Azure B2C: Where to Create DateTime Extension Attribute to be used in Custom Policy- Portal or Custom Policy or Both?

我需要在数据类型为“DateTime”的自定义策略中使用扩展属性。我定义声明类型如下。

<ClaimType Id="extension_myAttribute">
        <DisplayName>myAttrbute</DisplayName>
        <DataType>dateTime</DataType>
        <UserHelpText>This is for X</UserHelpText>
      </ClaimType>

我希望能够将此属性与当前时间进行比较,从而指导用户旅程。但是,当我查看 application insights 时,该值为“未定义”,因此将其与包含当前时间的声明类型进行比较对我没有好处。即使我将它添加到依赖方文件中的 OutputClaims,该属性也作为声明丢失。

Q1。以这种方式声明是否足够? Q2。我是否也需要在门户中的用户属性下创建它?我不确定,因为在门户中只有 int、boolean 和 string 数据类型可用。我可以使用其中任何一个代替 dateTime 吗?

编辑 这是使用属性

的转换
  <ClaimsTransformation Id="SetMyAttribute" TransformationMethod="GetCurrentDateTime">
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="extension_MyAttribute" TransformationClaimType="currentDateTime" />
    </OutputClaims>
  </ClaimsTransformation>

感谢您的帮助!

是的,正如您在自定义策略中定义的那样就足够了。你是对的,你不能在 Portal 中创建 dateTime 类型的自定义属性。

请参考这个link:https://github.com/azure-ad-b2c/samples/tree/master/policies/force-password-reset-after-90-days

这是为了在 90 天后重置密码。这肯定与您要实现的内容有关。

您需要在技术配置文件的输入或输出声明转换中调用您的声明转换。并从您的用户旅程中参考该技术资料。然后输出并发行到token中。

非常感谢你们的努力。在我的场景中,我需要在登录期间更新我的扩展属性,而不是像建议示例中那样注册。为了解决这个问题,我在 Azure AD 声明提供程序中添加了一个额外的 AAD-XXX 技术配置文件,它可以执行 'write' 操作但具有 RaiseErrorIfClaimsPrincipalAlreadyExists => 'false'。这使我能够在 InputClaimsTransformation 元素中调用我的声明转换,然后使用 PersistedClaims 元素写入 AAD。像下面这样的东西。我希望这对其他人有帮助。

<TechnicalProfile Id="AAD-XXXX">
  <Metadata>
    <Item Key="Operation">Write</Item>
    <Item Key="RaiseErrorIfClaimsPrincipalAlreadyExists">false</Item>
  </Metadata>
  <InputClaimsTransformations>
    <!--call claims transformation-->
    <InputClaimsTransformation ReferenceId="MyClaimsTransformation" />
  </InputClaimsTransformations>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="objectId" />
  </InputClaims>
  <PersistedClaims>
    <!-- Required claims -->
    <PersistedClaim ClaimTypeReferenceId="objectId" />
    <PersistedClaim ClaimTypeReferenceId="userPrincipalName" />
    <PersistedClaim ClaimTypeReferenceId="displayName" />
    <PersistedClaim ClaimTypeReferenceId="extension_MyExtensionAttribute" />
  </PersistedClaims>
  <IncludeTechnicalProfile ReferenceId="AAD-Common" />
  <UseTechnicalProfileForSessionManagement ReferenceId="SM-AAD" /> 
</TechnicalProfile>