Create "B2C User" with Microsoft Graph API

Roei 51 Reputation points
2022-10-26T15:19:10.48+00:00

We are trying to use B2C for our customer user login flow, but we have decided to use the ROPC flow for the basic login flow. As a result, we have to implement the user creation during registration ourselves.

We have been creating users with the Microsoft Graph API but it seems that we can only create users with the email domain "@mytenant.onmicrosoft.com" instead of being able to make a "B2C User" which can have an email with any domain.

Is there a way to create "B2C Users" with the Microsoft graph API? (254388-screen-shot-2022-10-26-at-111558-am.pngSee screenshot showing the "B2C User" template from the "create user" menu in the Azure portal)

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
40,356 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JimmySalian-2011 42,191 Reputation points
    2022-10-26T15:36:23.003+00:00

    Hey Roi,

    Please check a similar thread and there is a code shared by the MSFT and also by the creator of the question and this should give you a good start - cannot-create-a-azure-b2c-user-via-ms-graph-api.html

    Hope this helps.
    JS

    ==
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

  2. CarlZhao-MSFT 43,486 Reputation points
    2022-10-27T02:53:42.96+00:00

    Hi @Roei

    Make sure you're using Azure AD-specific ROPC flow to get tokens.

    Then call the /users endpoint to create a B2C user with social and local account identities:

    POST https://graph.microsoft.com/v1.0/users  
    Content-type: application/json  
      
    {  
      "displayName": "John Smith",  
      "identities": [  
        {  
          "signInType": "userName",  
          "issuer": "contoso.onmicrosoft.com",  
          "issuerAssignedId": "johnsmith"  
        },  
        {  
          "signInType": "emailAddress",  
          "issuer": "contoso.onmicrosoft.com",  
          "issuerAssignedId": "jsmith@yahoo.com"  
        },  
        {  
          "signInType": "federated",  
          "issuer": "facebook.com",  
          "issuerAssignedId": "5eecb0cd"  
        }  
      ],  
      "passwordProfile" : {  
        "password": "password-value",  
        "forceChangePasswordNextSignIn": false  
      },  
      "passwordPolicies": "DisablePasswordExpiration"  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.