Azure AD B2C Custom Policy to Pre-Populate Email Field in Sign-up Flow

Introduction:

Azure B2C is a service that manages business-to-customer identity, allowing users to access applications and APIs through single sign-on (SSO) using their social and local account identities. This post is part of a series on Azure B2C Custom policies. For a better understanding, I recommend reading my previous blog about Azure B2C before continuing with this one.

In this blog, I’m going to show how to configure our Azure B2C custom policies to pre-populate the email address that is sent through the query string, while loading the sign-up page. If you are new to Azure AD B2C Custom policies development, please go through my last blog to get started with custom policies  

User Case:

A form from a web application collects the user’s email address, on submitting the form it will redirect the user to the Azure B2C Sign-up form, where the email address of the user is passed as a query string that should be read and bound in Azure AD B2C Sign up form for better user experience. 

Sign Up – Pre-Populate Email Field:

Step 1: Open TrustFrameworkExtension.xml file
Step 2: Use Claim resolver as a key-value parameter to read the query string value that passed on redirecting the user to the sign-up form.

Go to LocalAccountSignUpWithLogonEmail technical profile, and update the input claim

<InputClaims>
		  <InputClaim ClaimTypeReferenceId="email" DefaultValue="{OAUTH-KV:email}" AlwaysUseDefaultValue="true" />
  </InputClaims>

The above claim resolver {OAUTH-KV: email} will get an email address value from the query string with the key name “email”

Step 3: Next, it’s better to make the email address field as ready only since it is auto-populated

Define the claim user type as read-only for the email claim type, as given below

	<ClaimType Id="email">
			<DisplayName>Email Address</DisplayName>
			<DataType>string</DataType>
			<UserInputType>Readonly</UserInputType>
		</ClaimType> 

Step 4: Upload the extension file in Identity Experience Framework using the Azure portal

Test the Flow

Run the Sign-up flow from the Azure Portal

Endpoint of the signup flow in my B2C environment User details (b2clogin.com)

Endpoint with email query string https://gowthamcbe.b2clogin.com/gowthamcbe.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1A_SIGNUP&client_id=08294166-1ef2-420c-8826-09d2810041b0&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.ms&scope=openid&response_type=id_token&prompt=login&email=gowthamkk7@gmail.com

Query string

Sign up flow

The query string “email” value is bound to the Email field

Summary:

We have seen how to auto-populate the email address field in the sign-up flow using the claim resolver with Custom policies. We will see more customization features on Azure AD B2C in my upcoming blogs.

Github – TrustFrameworkExtension file

gowthamk91

One thought on “Azure AD B2C Custom Policy to Pre-Populate Email Field in Sign-up Flow

Leave a Reply

Discover more from Gowtham K

Subscribe now to keep reading and get access to the full archive.

Continue reading