Thank you for posting this in Microsoft Q&A.
I understand that you want to return phone number claim to Azure B2C Custom Policy Claims Provider.To get phone number claim to Azure B2C Custom Policy please follow below steps:
- Define a "Phone number" claim.
- Ask the user for their phone number.
- Persist the phone number to the user profile in the Azure AD B2C directory.
- Read the phone number claim from the Azure AD B2C directory on each sign-in.
- Return the phone number to your relying party application after sign-in or sign-up.
Define a claim:
Open the extensions file of your policy. For example, SocialAndLocalAccounts/
TrustFrameworkExtensions.xml
.
- Search for the BuildingBlocks element. If the element doesn't exist, add it.
- Locate the ClaimsSchema element. If the element doesn't exist, add it.
- Add the phone number claim to the ClaimsSchema element.
Add a claim to the user interface:
Find the ClaimsProviders element. Add a new phone number ClaimsProviders . I hope you have completed up to this step https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-user-input?pivots=b2c-custom-policy#add-a-claim-to-the-user-interface
Read and write a claim:
Use PersistedClaims
to write data to the user profile and OutputClaims
to read data from the user profile within the respective Active Directory technical profiles.
Include a claim in the token:
To return the phone number claim back to the relying party application, add an output claim to the SocialAndLocalAccounts/SignUpOrSignIn.xml
file. The output claim will be added into the token after a successful user journey and will be sent to the application.
<RelyingParty>
<DefaultUserJourney ReferenceId="SignUpOrSignIn" />
<TechnicalProfile Id="PolicyProfile">
<DisplayName>PolicyProfile</DisplayName>
<Protocol Name="OpenIdConnect" />
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="givenName" />
<OutputClaim ClaimTypeReferenceId="surname" />
<OutputClaim ClaimTypeReferenceId="email" />
<OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub"/>
<OutputClaim ClaimTypeReferenceId="identityProvider" />
<OutputClaim ClaimTypeReferenceId="tenantId" AlwaysUseDefaultValue="true" DefaultValue="{Policy:TenantObjectId}" />
<OutputClaim ClaimTypeReferenceId="phoneNumber" DefaultValue="" />
</OutputClaims>
<SubjectNamingInfo ClaimType="sub" />
</TechnicalProfile>
</RelyingParty>
Upload the policy files that you previously changed and test your updated custom policy. The token sent back to your application includes the phone number
claim.
For your reference, please refer this document: https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-user-input?pivots=b2c-custom-policy
The ClaimsTransformations element contains a list of claims transformation functions that can be used in user journeys as part of a custom policy. A claims transformation converts a given claim into another one. To ConvertPhoneNumberClaimToString
please refer this document: https://learn.microsoft.com/en-us/azure/active-directory-b2c/phone-number-claims-transformations#example-of-convertphonenumberclaimtostring
Thanks,
Navya.
Hope this helps. Do let us know if you any further queries.