Search code examples
azuremicrosoft-graph-apiazure-ad-b2c

Not able to create users using identities in Azure AD B2C using Microsoft Graph API


I'm trying to create local account (like abc@yahoo.com) in Azure AD B2C using identities.

This is the document I followed: https://learn.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0&tabs=http#example-2-create-a-user-with-social-and-local-account-identities.

Below is the request payload:

{  
  "displayName": "John Smith",  
  "identities": [  
    {
      "signInType": "emailAddress",
      "issuer": "mytenant.onmicrosoft.com",
      "issuerAssignedId": "jsmith@yopmail.com" 
    }
  ],
  "passwordProfile": { 
    "password": "Welcome@1",    
    "forceChangePasswordNextSignIn": false  
  },
  "passwordPolicies": "DisablePasswordExpiration"
}

This is the response I'm getting:

"error": {
  "code": "Request_BadRequest",
  "message": "Property userPrincipalName value is required but is empty or missing."
}

First it was throwing an error for accountEnabled, mailNickname, so added them in payload, then it was throwing an error for userPrincipalName.

If I add userPrincipalName in the payload, it was throwing an error like this:

{
   "code": "Request_BadRequest",
   "message": "Property creationType is invalid."
}

How can I create users using identities in Azure AD B2C using Microsoft Graph API?


Solution

  • This is an example of attributes that work across all my tenants:

    { "accountEnabled": true, "displayName": "Test User", "mailNickname": "TestU", "userPrincipalName": "TestU@tenant.onmicrosoft.com", "passwordProfile" : { "forceChangePasswordNextSignIn": true, "password": "xWwvJ]6NMw+bWH-d" } }

    Do you still get the error with something like this?

    Update

    For multiple identities, something like this works:

    "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" } ]