Customising the phone drop down in Azure AD B2C

Rory Braybrook
The new control plane
2 min readFeb 23, 2021

There is a sample B2C custom policy to onboard users for MFA and for users to authenticate using MFA.

It uses this flow:

When you run the policy, you select e.g. that you want to use phone for MFA.

And then you get a drop-down for every single country.

But what if you only have users in Australia and New Zealand?

The original list is found in the “Localisation string ID”.

Look under “countryList”:

<LocalizedString ElementType="UxElement" StringId="countryList">{"DEFAULT":"Country/Region","AF":"Afghanistan","AX":"Åland Islands","AL":"Albania","DZ":"Algeria","AS":"American Samoa",..., "GB":"United Kingdom","US":"United States","UY":"Uruguay","UZ":"Uzbekistan","VU":"Vanuatu","VA":"Vatican City","VE":"Venezuela","VN":"Vietnam","WF":"Wallis and Futuna","YE":"Yemen","ZM":"Zambia","ZW":"Zimbabwe"}</LocalizedString>

We want the countryList to look like:

<LocalizedString ElementType="UxElement" StringId="countryList">{"DEFAULT":"Country/Region","AU":"Australia","NZ":"New Zealand"}</LocalizedString>

To do this we use:

<ContentDefinitions>
<ContentDefinition Id="api.phonefactor">
<LocalizedResourcesReferences MergeBehavior="ReplaceAll">
<LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.phonefactor.en"/>
</LocalizedResourcesReferences>
</ContentDefinition>
</ContentDefinitions>
<Localization Enabled="true">
<SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll">
<SupportedLanguage>en</SupportedLanguage>
</SupportedLanguages>
<LocalizedResources Id="api.phonefactor.en">
<LocalizedStrings>
<!-- Localize the country list -->
<LocalizedString ElementType="UxElement" StringId="countryList">{"DEFAULT":"Country/Region","AU":"Australia","NZ":"New Zealand"}</LocalizedString>
</LocalizedStrings>
</LocalizedResources>
</Localization>

And the result is:

If you just wanted NZ, you could simply add the country code (+64) to the phone number.

The InputClaim is substituted in the {0} construct.

<ClaimsTransformation Id="AddCountryCodeToPhoneNumber" TransformationMethod="FormatStringClaim">
<InputClaims>
<InputClaim ClaimTypeReferenceId="nationalNumber" TransformationClaimType="inputClaim" />
</InputClaims>
<InputParameters>
<InputParameter Id="stringFormat" DataType="string" Value="+64{0}" />
</InputParameters>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="nationalNumber" TransformationClaimType="outputClaim" />
</OutputClaims>
</ClaimsTransformation>

In this case, you could use:

<LocalizedString ElementType="UxElement" StringId="countryList">{}</LocalizedString>

All good!

--

--

Rory Braybrook
The new control plane

NZ Microsoft Identity dude and MVP. Azure AD/B2C/ADFS/Auth0/identityserver. StackOverflow: https://bit.ly/2XU4yvJ Presentations: http://bit.ly/334ZPt5