1

I am using 'DisplayControl_TrustFrameworkExtensions' custom policy in ADB2C to customize email templates. I have referred to this link to modify Custom policy.

I am using the technical profiles below.

<TechnicalProfiles>
  <TechnicalProfile Id="GenerateOtp">
    <DisplayName>Generate one time password</DisplayName>
    <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.OneTimePasswordProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    <Metadata>
      <Item Key="Operation">GenerateCode</Item>
      <Item Key="CodeExpirationInSeconds">1200</Item>
      <Item Key="CodeLength">6</Item>
      <Item Key="CharacterSet">0-9</Item>
      <Item Key="ReuseSameCode">true</Item>
      <Item Key="NumRetryAttempts">5</Item>
    </Metadata>
    <InputClaims>
      <InputClaim ClaimTypeReferenceId="email" PartnerClaimType="identifier" />
    </InputClaims>
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="otp" PartnerClaimType="otpGenerated" />
    </OutputClaims>
  </TechnicalProfile>

  <TechnicalProfile Id="VerifyOtp">
    <DisplayName>Verify one time password</DisplayName>
    <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.OneTimePasswordProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    <Metadata>
      <Item Key="Operation">VerifyCode</Item>
    </Metadata>
    <InputClaims>
      <InputClaim ClaimTypeReferenceId="email" PartnerClaimType="identifier" />
      <InputClaim ClaimTypeReferenceId="verificationCode" PartnerClaimType="otpToVerify" />
    </InputClaims>
  </TechnicalProfile>
 </TechnicalProfiles>

 <TechnicalProfile Id="SendOtp">
  <DisplayName>Use SendGrid's email API to send the code the the user</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
  <Metadata>
    <Item Key="ServiceUrl">https://api.sendgrid.com/v3/mail/send</Item>
    <Item Key="AuthenticationType">Bearer</Item>
    <Item Key="SendClaimsIn">Body</Item>
    <Item Key="ClaimUsedForRequestPayload">emailRequestBody</Item>
  </Metadata>
  <CryptographicKeys>
    <Key Id="BearerAuthenticationToken" StorageReferenceId="B2C_1A_SendGridSecret" />
  </CryptographicKeys>
  <InputClaimsTransformations>
    <InputClaimsTransformation ReferenceId="GenerateEmailRequestBody" />
  </InputClaimsTransformations>
  <InputClaims>
    <InputClaim ClaimTypeReferenceId="emailRequestBody" />
  </InputClaims>
</TechnicalProfile>

When I use this policy and run flow on azure portal, I get redirected to the login page. From there I can come to the sign-up page where users need to enter their email address and verify the same. Once I click on 'Send Verification Code' then I am getting the below error.

enter image description here

  • Either you have some firewall issues or the requestBody is wrong or you haven't set up SendGrid properly e.g. API key. – rbrayb Mar 30 '22 at 20:35
  • Yep, issue was with sendgrid template; I created legacy template instead of dynamic template. After creating dynamic template it started working as expected. – Jaydeep Suryawanshi Mar 31 '22 at 12:16

1 Answers1

1

Thank you Jaydeep Suryawanshi for your Update. Posting this as an answer to help other community members if they encounter the same issue.

To set up custom Email Verification with SendGrid, make sure to create a dynamic transactional template as mentioned in this Microsoft Doc

SendGrid has two types of templates for transactional email:

  • Dynamic transactional templates: These templates allow complex logic to be coded in the template itself.
  • Legacy transactional templates: These templates allow only simple key-value substitution and don’t specify a particular template syntax

In legacy templates, there are some attributes like merge field format where you have to set them manually and have to include specific field delimiters which is more difficult and error-prone.

In Dynamic templates, mostly parameters will be fetched dynamically which is less error-prone compared to legacy templates.

So, it is recommended to create dynamic templates than legacy templates.

To know how to create dynamic templates in detail, refer this: How to send an email with Dynamic Transactional Templates | Twilio (sendgrid.com)

Sridevi
  • 10,599
  • 1
  • 4
  • 17