Hi @Vaibhav Chaudhary, to get the country code and mobile number separately from the Azure AD B2C MFA number, you can use the GetNationalNumberAndCountryCodeFromPhoneNumberString
claims transformation in your custom policy. This claims transformation extracts the country/region code and the national number from the input claim, and optionally throws an exception if the supplied phone number isn't valid.
Here's an example of how you can use this claims transformation in your custom policy:
- Define the
phoneNumber
claim in yourClaimsSchema
section:
<ClaimType Id="phoneNumber">
<DisplayName>Phone Number</DisplayName>
<DataType>string</DataType>
<UserHelpText>Enter your phone number.</UserHelpText>
<UserInputType>PhoneNumber</UserInputType>
<Restriction>
<Pattern RegularExpression="^\+(?:[0-9] ?){6,14}[0-9]$"/>
</Restriction>
</ClaimType>
- Define the
countryCode
andnationalNumber
claims in yourClaimsSchema
section:
<ClaimType Id="countryCode">
<DisplayName>Country Code</DisplayName>
<DataType>string</DataType>
</ClaimType>
<ClaimType Id="nationalNumber">
<DisplayName>National Number</DisplayName>
<DataType>string</DataType>
</ClaimType>
- Define the
GetNationalNumberAndCountryCodeFromPhoneNumberString
claims transformation in yourClaimsTransformations
section:
<ClaimsTransformation Id="GetNationalNumberAndCountryCodeFromPhoneNumberString" TransformationMethod="GetNationalNumberAndCountryCodeFromPhoneNumberString">
<InputClaims>
<InputClaim ClaimTypeReferenceId="phoneNumber" TransformationClaimType="inputClaim" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="countryCode" TransformationClaimType="outputClaim" />
<OutputClaim ClaimTypeReferenceId="nationalNumber" TransformationClaimType="outputClaim" />
</OutputClaims>
</ClaimsTransformation>
- Use the
GetNationalNumberAndCountryCodeFromPhoneNumberString
claims transformation in yourTechnicalProfile
to get thecountryCode
andnationalNumber
claims:
<TechnicalProfile Id="PhoneFactor-InputOrVerify">
<DisplayName>PhoneFactor</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.PhoneFactorVerificationProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ContentDefinitionReferenceId">api.phonefactor</Item>
<Item Key="ManualPhoneNumberEntryAllowed">true</Item>
<Item Key="setting.authenticationMode">sms</Item>
<Item Key="setting.pinRequired">false</Item>
<Item Key="setting.timeoutSeconds">120</Item>
<Item Key="setting.retryLimit">0</Item>
<Item Key="setting.retryInterval">60</Item>
</Metadata>
<InputClaimsTransformations>
<InputClaimsTransformation ReferenceId="GetNationalNumberAndCountryCodeFromPhoneNumberString" />
</InputClaimsTransformations>
<InputClaims>
<InputClaim ClaimTypeReferenceId="countryCode" />
<InputClaim ClaimTypeReferenceId="nationalNumber" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="Verified.strongAuthenticationPhoneNumber" />
<OutputClaim ClaimTypeReferenceId="phoneFactorVerificationCode" />
<OutputClaim ClaimTypeReferenceId="phoneFactorSelectedMethod" />
</OutputClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James