Skip to content

Commit

Permalink
Date claims readme plus more CTs
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelhor committed Feb 9, 2022
1 parent f0cc20b commit cd78688
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 12 deletions.
8 changes: 4 additions & 4 deletions claims-transformation/date/CT_AssertDateTimeIsGreaterThan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
<InputClaim ClaimTypeReferenceId="date2" TransformationClaimType="rightOperand" />
</InputClaims>
<InputParameters>
<InputParameter Id="AssertIfEqualTo" DataType="boolean" Value="true" />
<InputParameter Id="AssertIfEqualTo" DataType="boolean" Value="false" />
<InputParameter Id="AssertIfRightOperandIsNotPresent" DataType="boolean" Value="false" />
<InputParameter Id="TreatAsEqualIfWithinMillseconds" DataType="int" Value="60" />
<InputParameter Id="TreatAsEqualIfWithinMillseconds" DataType="int" Value="30000" />
</InputParameters>
</ClaimsTransformation>
</ClaimsTransformations>
Expand All @@ -63,13 +63,13 @@
<OutputClaim ClaimTypeReferenceId="date2" Required="true" />
</OutputClaims>
<ValidationTechnicalProfiles>
<ValidationTechnicalProfile ReferenceId="ClaimsTransformation-AssertDateTimeIsGreaterThan" />
<ValidationTechnicalProfile ReferenceId="ExperimentalValidation" />
</ValidationTechnicalProfiles>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>

<!--Validation technical profile-->
<TechnicalProfile Id="ClaimsTransformation-AssertDateTimeIsGreaterThan">
<TechnicalProfile Id="ExperimentalValidation">
<DisplayName>Unit test</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.ClaimsTransformationProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<OutputClaims>
Expand Down
8 changes: 2 additions & 6 deletions claims-transformation/date/CT_DateTimeComparison.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ClaimType Id="result">
<DisplayName>The result of this claims transformation (result)</DisplayName>
<DataType>boolean</DataType>
<UserInputType>Paragraph</UserInputType>
<UserInputType>Readonly</UserInputType>
</ClaimType>
</ClaimsSchema>

Expand All @@ -36,7 +36,7 @@
</InputClaims>
<InputParameters>
<InputParameter Id="operator" DataType="string" Value="later than" />
<InputParameter Id="timeSpanInSeconds" DataType="int" Value="0" />
<InputParameter Id="timeSpanInSeconds" DataType="int" Value="5" />
</InputParameters>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="result" TransformationClaimType="result" />
Expand Down Expand Up @@ -77,13 +77,9 @@
<Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="dateTime1" />
<InputClaim ClaimTypeReferenceId="dateTime2" />
<InputClaim ClaimTypeReferenceId="result" />
</InputClaims>
<DisplayClaims>
<DisplayClaim ClaimTypeReferenceId="dateTime1" />
<DisplayClaim ClaimTypeReferenceId="dateTime2" />
<DisplayClaim ClaimTypeReferenceId="result" />
</DisplayClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
Expand Down
4 changes: 2 additions & 2 deletions claims-transformation/date/CT_GetCurrentDateTime.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ClaimsSchema>

<ClaimsTransformations>
<ClaimsTransformation Id="Getresult" TransformationMethod="GetCurrentDateTime">
<ClaimsTransformation Id="GetResult" TransformationMethod="GetCurrentDateTime">
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="result" TransformationClaimType="currentDateTime" />
</OutputClaims>
Expand All @@ -38,7 +38,7 @@
<Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
</Metadata>
<InputClaimsTransformations>
<InputClaimsTransformation ReferenceId="Getresult" />
<InputClaimsTransformation ReferenceId="GetResult" />
</InputClaimsTransformations>
<InputClaims>
<InputClaim ClaimTypeReferenceId="result" />
Expand Down
115 changes: 115 additions & 0 deletions claims-transformation/date/CT_IsTermsOfUseConsentRequired.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TrustFrameworkPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06" PolicySchemaVersion="0.3.0.0"
TenantId="yourtenant.onmicrosoft.com"
PolicyId="B2C_1A_CT_IsTermsOfUseConsentRequired"
PublicPolicyUri="http://yourtenant.onmicrosoft.com/B2C_1A_CT_IsTermsOfUseConsentRequired">

<BasePolicy>
<TenantId>yourtenant.onmicrosoft.com</TenantId>
<PolicyId>B2C_1A_TrustFrameworkExtensions</PolicyId>
</BasePolicy>

<BuildingBlocks>
<ClaimsSchema>
<ClaimType Id="dateTime1">
<DisplayName>First date (dateTime1)</DisplayName>
<DataType>dateTime</DataType>
<UserInputType>DateTimeDropdown</UserInputType>
</ClaimType>
<ClaimType Id="result">
<DisplayName>The result of this claims transformation (result)</DisplayName>
<DataType>boolean</DataType>
<UserInputType>Readonly</UserInputType>
</ClaimType>
</ClaimsSchema>

<ClaimsTransformations>
<ClaimsTransformation Id="CompareDates" TransformationMethod="IsTermsOfUseConsentRequired">
<InputClaims>
<InputClaim ClaimTypeReferenceId="dateTime1" TransformationClaimType="termsOfUseConsentDateTime" />
</InputClaims>
<InputParameters>
<InputParameter Id="termsOfUseTextUpdateDateTime" DataType="dateTime" Value="2022-01-15T00:00:00" />
</InputParameters>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="result" TransformationClaimType="result" />
</OutputClaims>
</ClaimsTransformation>
</ClaimsTransformations>
</BuildingBlocks>

<ClaimsProviders>
<ClaimsProvider>
<DisplayName>Unit tests</DisplayName>
<TechnicalProfiles>
<TechnicalProfile Id="ExperimentalTechnicalProfile">
<DisplayName>Unit test</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="dateTime1" DefaultValue="2022-03-01T00:00:00.100000Z" AlwaysUseDefaultValue="true" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="dateTime1" />
</OutputClaims>
<OutputClaimsTransformations>
<OutputClaimsTransformation ReferenceId="CompareDates" />
</OutputClaimsTransformations>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>

<TechnicalProfile Id="ResultTechnicalProfile">
<DisplayName>Unit test</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ContentDefinitionReferenceId">api.selfasserted</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="result" />
</InputClaims>
<DisplayClaims>
<DisplayClaim ClaimTypeReferenceId="result" />
</DisplayClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
</ClaimsProviders>

<UserJourneys>
<UserJourney Id="UnitTestJourney">
<OrchestrationSteps>
<OrchestrationStep Order="1" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="ExperimentalTechnicalProfile" TechnicalProfileReferenceId="ExperimentalTechnicalProfile" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="2" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="ResultTechnicalProfile" TechnicalProfileReferenceId="ResultTechnicalProfile" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="3" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="JwtIssuer" />
</OrchestrationSteps>
</UserJourney>
</UserJourneys>

<RelyingParty>
<DefaultUserJourney ReferenceId="UnitTestJourney" />
<TechnicalProfile Id="PolicyProfile">
<DisplayName>PolicyProfile</DisplayName>
<Protocol Name="OpenIdConnect" />
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub" DefaultValue="1234" />
<OutputClaim ClaimTypeReferenceId="tenantId" AlwaysUseDefaultValue="true" DefaultValue="{Policy:TenantObjectId}" />

<!-- Unit test claims-->
<OutputClaim ClaimTypeReferenceId="dateTime1" />
<OutputClaim ClaimTypeReferenceId="result" />
</OutputClaims>
<SubjectNamingInfo ClaimType="sub" />
</TechnicalProfile>
</RelyingParty>
</TrustFrameworkPolicy>
74 changes: 74 additions & 0 deletions claims-transformation/date/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Date claims transformations unit tests

This folder contains examples for Azure AD B2C date claims transformations unit tests. For more information, see [Date claims transformations](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations).

## AssertDateTimeIsGreaterThan

Asserts whether the `date1` claim is greater than the `date2` claim. An error is thrown if `date2` is later than `date1`. The transformation treats values as equal if they are within 5 minutes (30000 milliseconds) difference. It won't throw an error if the values are equal because `AssertIfEqualTo` is set to `false`.

The unit test defines the following elements:

- **ExperimentalTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile renders the `date1` and `date2` claims with default values (you can change the values). Select *Continue* the run the **ExperimentalValidation** validation technical profile.
- **ExperimentalValidation** - [claims transformation](https://docs.microsoft.com/azure/active-directory-b2c/claims-transformation-technical-profile) type of [validation technical profile](https://docs.microsoft.com/azure/active-directory-b2c/validation-technical-profile). This validation technical profile invokes the **AssertDates** claims transformation, which runs the assertion.
- **AssertDates** claims transformation - the unit test.

[Live demo](https://b2clivedemo.b2clogin.com/b2clivedemo.onmicrosoft.com/B2C_1A_CT_AssertDateTimeIsGreaterThan/oauth2/v2.0/authorize?client_id=cfaf887b-a9db-4b44-ac47-5efff4e2902c&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=openid&response_type=id_token&prompt=login), [Quick deploy](https://b2ciefsetupapp.azurewebsites.net/), [documentation](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations#assertdatetimeisgreaterthan)

## ConvertDateTimeToDateClaim

Converts the `dateTimeClaims` claim (type of dateTime), into `result` claim (type of date). After the claims transformation is completed the time part of the date will be removed.

The unit test defines the following elements:

- **ExperimentalTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile first calls the **GetSystemDateTime** adn **ConvertToDate** input claims transformations. Then, renders the `dateTimeClaims` with default value, and `result` claims with the result value of this claims transformation.
- **GetSystemDateTime** claims transformation - Set default value to the `dateTimeClaims` claim using [GetCurrentDateTime](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations#getcurrentdatetime) claims transformation.
- **ConvertToDate** claims transformation - the unit test.

[Live demo](https://b2clivedemo.b2clogin.com/b2clivedemo.onmicrosoft.com/B2C_1A_CT_ConvertDateTimeToDateClaim/oauth2/v2.0/authorize?client_id=cfaf887b-a9db-4b44-ac47-5efff4e2902c&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=openid&response_type=id_token&prompt=login), [Quick deploy](https://b2ciefsetupapp.azurewebsites.net/), [documentation](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations#convertdatetimetodateclaim)

## ConvertDateToDateTimeClaim

Converts the `dateClaim` claim (type of date), into `result` claim (type of dateTime). After the claims transformation is completed the 00:00:00 time will be added to the `result` claim.

The unit test defines the following elements:

- **ExperimentalTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile renders the `dateClaim` claim with default value (you can change the value). Then it calls the **ConvertToDateTime** output claims transformation to convert the date to dateTime.
- **ConvertToDateTime** claims transformation - the unit test.

[Live demo](https://b2clivedemo.b2clogin.com/b2clivedemo.onmicrosoft.com/B2C_1A_CT_ConvertDateToDateTimeClaim/oauth2/v2.0/authorize?client_id=cfaf887b-a9db-4b44-ac47-5efff4e2902c&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=openid&response_type=id_token&prompt=login), [Quick deploy](https://b2ciefsetupapp.azurewebsites.net/), [documentation](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations#convertdatetodatetimeclaim)

## DateTimeComparison

Determines if the `dateTime1` claim plus the `timeSpanInSeconds` parameter (5 seconds) is later than the `dateTime2` claim. The `result` claim is a new Boolean claim with a value of `true` or `false`.

The unit test defines the following elements:

- **ExperimentalTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile renders the `dateTime1` and `dateTime2` where you can choose the dates to compare. Then it runs the **CompareDates** output claims transformation. Select *Continue* the run the next orchestration step that shows the result.
- **ResultTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile shows the `result` of this unit test.
- **CompareDates** claims transformation - the unit test.

[Live demo](https://b2clivedemo.b2clogin.com/b2clivedemo.onmicrosoft.com/B2C_1A_CT_DateTimeComparison/oauth2/v2.0/authorize?client_id=cfaf887b-a9db-4b44-ac47-5efff4e2902c&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=openid&response_type=id_token&prompt=login), [Quick deploy](https://b2ciefsetupapp.azurewebsites.net/), [documentation](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations#datetimecomparison)


## GetCurrentDateTime

Shows how to get the current data and time into the `result` claim.

The unit test defines the following elements:

- **ExperimentalTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile first calls the **GetResult** input claims transformation. Then, shows the `result` claim with the current date time.
- **GetResult** claims transformation - the unit test.

[Live demo](https://b2clivedemo.b2clogin.com/b2clivedemo.onmicrosoft.com/B2C_1A_CT_DateTimeComparison/oauth2/v2.0/authorize?client_id=cfaf887b-a9db-4b44-ac47-5efff4e2902c&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=openid&response_type=id_token&prompt=login), [Quick deploy](https://b2ciefsetupapp.azurewebsites.net/), [documentation](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations#datetimecomparison)

## IsTermsOfUseConsentRequired

Determines if the `dateTime1` easier than the `2022-01-15T00:00:00`. The `result` claim is a new Boolean claim with a value of `true` or `false`. If you select date that is later than `2022-01-15T00:00:00` the result will be `false`. Otherwise, it will be `true`.

The unit test defines the following elements:

- **ExperimentalTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile renders the `dateTime1` where you can choose a date to compare with `2022-01-15T00:00:00`. Then it runs the output claims transformation. Select *Continue* the run the next orchestration step that shows the result.
- **ResultTechnicalProfile** - [self-asserted](https://docs.microsoft.com/azure/active-directory-b2c/self-asserted-technical-profile) technical profile. This technical profile shows the `result` of this unit test.
- **CompareDates** claims transformation - the unit test. The `2022-01-15T00:00:00` date is configure in this claims transformation.

[Live demo](https://b2clivedemo.b2clogin.com/b2clivedemo.onmicrosoft.com/B2C_1A_CT_ConvertDateTimeToDateClaim/oauth2/v2.0/authorize?client_id=cfaf887b-a9db-4b44-ac47-5efff4e2902c&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=openid&response_type=id_token&prompt=login), [Quick deploy](https://b2ciefsetupapp.azurewebsites.net/), [documentation](https://docs.microsoft.com/azure/active-directory-b2c/date-transformations#istermsofuseconsentrequired).

0 comments on commit cd78688

Please sign in to comment.