Share via

Display custom error message to user on signup if email address entered 2 times differ

Sandor Juhasz 1 Reputation point
2021-12-15T11:47:50.577+00:00

I've created a custom policy for Azure AD B2C to define a user sign up process. It works as expected.

Now I want to extend the policy to have a second text field to confirm an eMail address. So I'm simply using a claims transformation to assert that the user entered the correct email twice (of type AssertStringClaimsAreEqual). I used the following example/documentation:
https://learn.microsoft.com/en-us/azure/active-directory-b2c/string-transformations#assertstringclaimsareequal
https://learn.microsoft.com/en-us/azure/active-directory-b2c/claims-transformation-technical-profile#use-a-validation-technical-profile
https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/active-directory-b2c/string-transformations.md#assertstringclaimsareequal

My problem: if I enter 2 mismatching email addresses, I always get the standard error message for mismatching password entries ("error_passwordEntryMismatch", I can overwrite that with a custom message but then the error message for mismatching passwords would be misleading).
I can't see the error message I defined using "UserMessageIfClaimsTransformationStringsAreNotEqual"in the Metadata section of the TechnicalProfile.

I tried a lot like explicitly defining "RaiseErrorIfClaimsTransformationStringsAreNotEqual" = true, moving technical profiles around, set "ContinueOnError" = false for the ValidationTechnicalProfile reference, put the custom error message to the localization section and so on.
The custom error message that the entered eMail addresses mismatch won't be displayed. I always end up with "The password entry fields do not match. Please enter the same password in both fields and try again."

Can somebody please help here?

Microsoft Security | Microsoft Entra | Microsoft Entra External ID

2 answers

Sort by: Most helpful
  1. Anonymous
    2022-01-03T21:00:30.927+00:00

    Edit: Solution from @Sandor Juhasz -

    The solution: do not name your matching email field "reenterEmail" as I did because it seems that there is some whacky StartsWith logic on the claim type name which seems to look for "reenterSomethingBlabla" and interprets that as "somebody is trying to validate a password against another field".

    I renamed the second eMail field to "confirmEmail" and it displays the error message as it should be using the div id="claimVerificationServerError" in the rendered output.

    Hi @Sandor Juhasz , sorry for the delay in response, I was off for the Holidays. Please review this thread as it can most likely fix your problem: https://stackoverflow.com/questions/62308594/in-azure-b2c-custom-policies-how-do-i-display-more-than-2-distinct-validation-m

    In essence, you can only have 1 distinct validation for that claims transformation. For the password validation you have to depend on the Self Asserted technical profile for its built-in password validation. The sample Jas provided in his reply has everything for that built-in validation to work.

    Please let me know if this works for you or if you get stuck.

    If this answer helped you, please mark it as "Verified" so other users may reference it.

    Thank you,
    James

    Was this answer helpful?


  2. Sandor Juhasz 1 Reputation point
    2021-12-17T08:04:47.577+00:00

    Hey James,

    Sure!

    This is my ClaimsTransformation to compare both eMail fields:

        <ClaimsTransformations>
          <ClaimsTransformation Id="AssertEmailAndReenterEmailAddressAreEqual" TransformationMethod="AssertStringClaimsAreEqual">
            <InputClaims>
              <InputClaim ClaimTypeReferenceId="reenterEmail" TransformationClaimType="inputClaim1" />
              <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="inputClaim2" />
            </InputClaims>
            <InputParameters>
              <InputParameter Id="stringComparison" DataType="string" Value="ordinalIgnoreCase" />
            </InputParameters>
          </ClaimsTransformation>
        </ClaimsTransformations>
    

    This is the TechnicalProfile which uses the Claims Transformation:

          <TechnicalProfiles>
            <TechnicalProfile Id="ValidateEmailAddress">
              <DisplayName>Check email address twice</DisplayName>
              <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.ClaimsTransformationProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
              <InputClaims>
                <InputClaim ClaimTypeReferenceId="reenterEmail" />
              </InputClaims>
              <OutputClaims>
                <OutputClaim ClaimTypeReferenceId="email" />
              </OutputClaims>
              <OutputClaimsTransformations>
                <OutputClaimsTransformation ReferenceId="AssertEmailAndReenterEmailAddressAreEqual" />
              </OutputClaimsTransformations>
              <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
            </TechnicalProfile>
    

    This is the SelfAsserted User Sign Up Profile using the "ValidateEmailAddress" Profile as a ValidationTechnicalProfile:

     <DisplayName>Self Asserted</DisplayName>
          <TechnicalProfiles>
            <TechnicalProfile Id="SelfAsserted-UserSignup">
              <DisplayName>User signup</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.signup</Item>
                <Item Key="setting.showCancelButton">false</Item>
                <Item Key="UserMessageIfClaimsTransformationStringsAreNotEqual">The email addresses you provided are not the same.</Item>
              </Metadata>
              <IncludeInSso>false</IncludeInSso>
              <InputClaims>
                <InputClaim ClaimTypeReferenceId="email" />
              </InputClaims>
              <DisplayClaims>
                <DisplayClaim ClaimTypeReferenceId="activationCode" Required="true" />
                <DisplayClaim ClaimTypeReferenceId="email" Required="true" />
                <DisplayClaim ClaimTypeReferenceId="reenterEmail" Required="true" />
                <DisplayClaim ClaimTypeReferenceId="newPassword" Required="true" />
                <DisplayClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
                <DisplayClaim ClaimTypeReferenceId="extension_TermsOfUseConsented" Required="true" />
                <DisplayClaim ClaimTypeReferenceId="extension_PrivacyPolicyConsented" Required="true" />
                <DisplayClaim ClaimTypeReferenceId="extension_NewsletterConsented" />
              </DisplayClaims>
              <OutputClaims>
                <OutputClaim ClaimTypeReferenceId="objectId" Required="true" />
                <OutputClaim ClaimTypeReferenceId="email" Required="true" />
                <OutputClaim ClaimTypeReferenceId="reenterEmail" Required="true" />
                <OutputClaim ClaimTypeReferenceId="newPassword" Required="true" />
                <OutputClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
                <OutputClaim ClaimTypeReferenceId="activationCode" Required="true" />
              </OutputClaims>
              <ValidationTechnicalProfiles>
                <ValidationTechnicalProfile ReferenceId="ValidateEmailAddress" ContinueOnError="false" />
                <ValidationTechnicalProfile ReferenceId="RestApi-ValidateActivationCode" />
                <ValidationTechnicalProfile ReferenceId="RestApi-VerifyEmailAddress" />
                <ValidationTechnicalProfile ReferenceId="AAD-CreateNewUser" />
              </ValidationTechnicalProfiles>
            </TechnicalProfile>
          </TechnicalProfiles>
    

    The comparison of the eMail works as expected, but I'm not able to get my custom error message displayed.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.