Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Azure AD user programmatically?

I understand there is azure portal to manage groups, user and etc.

Are there any ways to do it programmatically (either using web-api or sdk in C#)?

Thanks in advance.

like image 335
Code Korenge Avatar asked Jun 26 '17 09:06

Code Korenge


1 Answers

It is easy to create Azure AD users using the Microsoft Graph REST. Here is a code sample for your reference:

POST https://graph.microsoft.com/v1.0/users 
Authorization: Bearer {token}
Content-type: application/json

{
  "accountEnabled": true,
  "displayName": "displayName-value",
  "mailNickname": "mailNickname-value",
  "userPrincipalName": "[email protected]",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password-value"
  }
}

It also provides the corresponding library using C# from here. More detail about Microsoft Graph, you can refer the link below:

Overview of Microsoft Graph

Get access tokens to call Microsoft Graph

Create User

like image 88
Fei Xue - MSFT Avatar answered Sep 17 '22 02:09

Fei Xue - MSFT