Search code examples
azure-ad-b2cidentity-experience-framework

Set DefaultValue to DateTime.Now() Equivalent


How do I set a default value to the current date and time?

<OutputClaims>
    <OutputClaim ClaimTypeReferenceId="extension_MyCustomClaim" DefaultValue="DateTime.Now()">
</OutputClaims>

ClaimType for reference:

<ClaimType Id="extension_MyCustomClaim">
    <DisplayName>Some Date/Time</DisplayName>
    <DataType>date</DataType>
    <DefaultPartnerClaimTypes>
      <Protocol Name="OAuth2" PartnerClaimType="myCustomClaim" />
      <Protocol Name="OpenIdConnect" PartnerClaimType="myCustomClaim" />
    </DefaultPartnerClaimTypes>
    <AdminHelpText>Some date time</AdminHelpText>
    <UserInputType>TextBox</UserInputType>
</ClaimType>

Update

Unable to upload policy. Reason : Validation failed: 1 validation error(s) found in policy "B2C_1A_TRUSTFRAMEWORK_BUILDINGBLOCKS" of tenant "my-tenant.onmicrosoft.com".The OutputClaims mismatched in ClaimsTransformation with id "GetSystemDateTime" with TransformationMethod "GetCurrentDateTime".

The following OutputClaims were declared in the Policy but were not expected by the TransformMethod: [Date]currentDateTime. The following OutputClaims were expected by the TransformMethod but were not declared in the Policy: [DateTime]currentDateTime.

Wonder if I need an updated base.xml file? Thoughts? 💭


Solution

  • You can declare a claims transformation of type GetCurrentDateTime and then invoke this as an output claim transformation from the technical profile:

      <ClaimsTransformation Id="GetNow" TransformationMethod="GetCurrentDateTime">
        <OutputClaims>
          <OutputClaim ClaimTypeReferenceId="extension_MyCustomClaim" TransformationClaimType="currentDateTime" />
        </OutputClaims>
      </ClaimsTransformation>
    

    Also, the DataType of the ClaimType has to be dateTime

    <ClaimType Id="extension_MyCustomClaim">
        ...
        <DataType>dateTime</DataType>
        ...
    </ClaimType>