How to set custom claims for a user in Azure AD B2C

Yashwanth Reddy Yenugu 46 Reputation points
2020-04-07T11:23:03.067+00:00

I've created a new user by navigating to the users section. I've even created a custom user attribute in user attributes section. But how attributes for users?

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,663 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,665 questions
0 comments No comments
{count} vote

4 answers

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,311 Reputation points
    2020-04-07T11:36:00.35+00:00

    @Yashwanth Reddy Yenugu To use custom user attribute, you need to create a User Flow as documented here. When you Run User Flow, you need to choose sign-up to create a new user account.

    If you want to assign custom attribute to the existing user that you created from users section, you need to create Profile Update user flow and sign-in with that user to assign value to the custom attribute for that user. Make sure in the profile edit user flow, you select the custom attribute checkbox that you created. When you will run profile edit user flow, you will get an option to specify a value for the custom attribute.

    -----------------------------------------------------------------------------------------------------------

    Please "Accept as answer" wherever the information provided helps you to help others in the community.

    2 people found this answer helpful.

  2. soumi-MSFT 11,716 Reputation points Microsoft Employee
    2020-04-07T11:40:18.2+00:00

    @Yashwanth Reddy Yenugu , If you create a custom user attribute, then that attribute is not added to any user, but that attribute is connected with any of the user flows like signup-signin policy. When the user accesses the signup-signin policy, in that a text box appears to enter the value for that custom user attribute.

    You can read more about it here: https://learn.microsoft.com/en-us/azure/active-directory-b2c/user-flow-custom-attributes#use-a-custom-attribute-in-your-user-flow

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.

    1 person found this answer helpful.

  3. AmanpreetSingh-MSFT 56,311 Reputation points
    2020-04-14T15:10:52.64+00:00

    @Yashwanth Yenugu , Please find below the steps to extend Azure AD Schema and assign value to it by using Admin account via Graph API and not via IEF.

    1. Create a new application in App Registration under Azure AD.
    2. Once the application is created copy the Object ID.
    3. Open Graph Explorer by using https://developer.microsoft.com/en-us/graph/graph-explorer# url.
    4. Click on Sign in with Microsoft on the left and Sign in with Global Admin account who is a member of same directory and not added as external (guest) user.
    5. Click on Modify permissions > select Directory.AccessAsUser.All > click Modify Permissions.
    6. Click on Accept at consent page.
    7. In Graph Explorer, use following query. Where the <Tenant Name> is your_tenat.onmicrosoft.com in your case and <ObjectID of the application> is the value copied in Step 2.
      POST https://graph.microsoft.com/beta/<Tenant Name>/applications/< ObjectID of the application >/extensionProperties
    8. Use following text in the Request body. Since the targetObject is user, the attribute will be created for all Users in the tenant. Note: Please type the request body manually as with copy-paste Graph Explorer will not recognize some of the characters.
      {
      “name”: “Role”,
      “dataType”: “String”,
      “targetObjects”: {“User”]
      }
    9. To update the attribute with a value use following query:
      PATCH https://graph.microsoft.com/beta/users/globaladmin@your_tenant.onmicrosoft.com
      And use following Request Body:
      {
      "extension_e175b1fc21b144019cadxxxxxxxxxxxx_Role":"Admin"
      }
    10. To verify if the attribute is updated successfully run following query:
      GET https://graph.microsoft.com/beta/users/< User’s UPN or Object ID >

    -----------------------------------------------------------------------------------------------------------

    Please "Accept as answer" wherever the information provided helps you to help others in the community.

    1 person found this answer helpful.

  4. Gurpreet Arora 1 Reputation point
    2021-06-28T15:57:49.867+00:00

    Hey @AmanpreetSingh-MSFT can we add a new attribute during the time of Update User details using Graph API.

    Let say the User is already created using Facebook Login and details like Name, Country, etc stored in B2C. Now using Update method of Graph API I need to add new attributes such as Description and Language.

    Is it possible?

    When I try to add a new attribute during using Update method I get the following error.

    Code: Request_BadRequestMessage: One or more property values specified are invalid.Inner error

    0 comments No comments