Azure B2C Custom Policy , Add Custom User Attribute in Output Claims - azure

I have created custom policy for Interactive login in Azure AAD B2C
The Sign In / Sign Up works fine
However now I added Custom User Attribute in my B2C thru Portal, and updated so my custom policy also for "extension_UserRole" custom policy
However it is not showing in sign in as well as JWT , Below is my custom policy
https://github.com/menikhilmittal/policyb2c
Please suggest changes

Input claims are used to pre-populate fields.
You need to give the extension attribute a value (CopyClaim? from another attribute) and have it as an output in both read and write.
If an output in sign up e.g. it will create a text box that you can populate.
You have also used both email and login hint to populate it?

Related

Getting user attribute in sign in flow in Azure B2C

When i read the documentation from microsoft for Azure B2C, it mentions that we can collect user attributes during the sing up flow.
I have a requirement where i need to get a input from the user during the sign in flow. Other than the username and password entered during the sign in, i need the user to enter another field.
Is there an option to do the above in the sign in flow?
You need to use a custom policy.
It will allow you to add any extra pages and/or logic to any journey.
Samples: https://github.com/azure-ad-b2c/samples
Another way of collecting user input (eg. an additional field in the sign-up form) during sign-up without using custom policies is as follows:
In the Azure B2C set up an additional User Attribute of the type String
In the specific sign-in flow require this User Attribute to be collected.
If needed, you can customize the wording and default values used in the form by supplying a language override in the specific flow.

Azure AD B2C - get Custom attributes sets by Graph API in the token

After users has done the sign up I want to set some information and receive it in the token when they sign in.
In order to do that I am using custom attributes and setting the value using GraphAPI.
The way I add the custom attributes is as described here:
In your Azure AD B2C tenant, select User flows.
Select your policy (for example, "B2C_1_SignupSignin") to open it.
Select User attributes and then select the custom attribute (for example, "ShoeSize"). Click Save.
Select Application claims and then select the custom attribute.
Click Save.
Those attributes should not be a concern of the user so I am not doing the step number 3 and here is where the problem comes.
I am able to set/get the value of the custom attribute using Graph API but the attribute is not present in the token. If I do the step number 3 then the custom attribute appears in the token.
Is there any workaround to achieve having the custom attributes in the token without having them in the sign up screen?
The link above also says:
The custom attribute is now available in the list of User attributes
and for use in your user flows. A custom attribute is only created the
first time it is used in any user flow, and not when you add it to the
list of User attributes.
Which I believe is the reason why I can't see the attribute in the token, but I though that after setting it with GraphAPI and being able to read it, it would be in the token.
It's not true.
Based on my test, if we don't do the step number 3 but do the step number 4, the custom attribute won't appear in sign up page but still can be included in the token.
Please make sure that you have updated the custom attribute for the signed-in user and use the same user to sign in with that user flow where you didn't do the step number 3 but did the step number 4.
Kindly check it.

Azure B2C - My customer would like to send the country code value on a custom claim he added on the custo policy

I'm assisting a client which is working on a B2C custom claim. He has created the custom claim as scollarCountryCode, and would like to know if its possible to pull the country code attribute value and send this value in this custom claim.
I assume that your client has finished the steps in Add claims and customize user input using custom policies in Azure Active Directory B2C.
So now you can get the custom attribute in user interface and token.
If you want to query the custom attribute, just use Microsoft Graph API Get a user.
Get https://graph.microsoft.com/beta/users/{id | userPrincipalName}
You can get the custom attribute in the response. Its format is like this:
"extension_8adbe99219ca4e689a5030b5af068847_scollarCountryCode": 00123
Please note 8adbe99219ca4e689a5030b5af068847 in this case is the client id of WebApp-GraphAPI-DirectoryExtensions, which is the built-in enterprise app in the B2C tenant. You will have a different one.

Is there a way to define the Display Name in the Sign up and Sign in user flow in Azure AD B2C?

Is there a way to define the Display Name(label) and User Input type for the Sign up and Sign in user flow in Azure AD B2C out of the box?
We are having several custom attributes for which we need to set a user-friendly display name. However, the recommended Sign up and sign In policy doesn’t seem to support this out of the box. The Sign Up only policy has UI to define the Display Name (in Label). We can use two separate policies Sign Up and Sign In, but the later doesn’t support to select templates.
Currently there is no direct UI for Sign up and sign In policy and Sign In policy. You need to customize the label manually by editing the file.
Reference:
https://learn.microsoft.com/en-us/azure/active-directory-b2c/user-flow-language-customization
https://learn.microsoft.com/en-us/azure/active-directory-b2c/customize-ui-overview

Azure B2C custom attribute/claim added to existing user directory throws error on sign in

I have a custom policy which adds a custom value, HoldingId, to new users who sign up (using these docs) as the value is passed to the policy via the token (along with verified_email).
I was hoping to not need to create a custom policy for sign in, so used the Azure Portal UI to create the custom attribute against the b2c-extensions-app application (and am using the respective client and object ids to line it up with the custom policy), and using the Portal have added this custom attribute to the sign up/sign in policy claims.
Using the Graph API, I have been able to successfully confirm that the custom value is saving against newly signed up users (returning as extension_[AppId]_HoldingId), and these new users are able to sign in subsequently without issue using the built in sign in/sign up policy.
However, any users which already existed in the directory are no longer able to sign in. Unfortunately, because it's a built-in policy, I'm not sure of a way to dig into the logs a-la App Insights to see what's going on.
My suspicion is that because these existing users don't have this custom attribute against them, the built-in sign up/sign in policy is attempting to get this value and failing.
Is it possible to get the built-in policies to ignore this attribute on users who don't have this attribute set, or will I need to create a custom policy to handle this scenario with a default value?
For context, the HoldingId is not required for existing users (application needs to be backwards compatible). This is also my first venture into B2C, so I'm still learning many of these concepts.

Resources