Facing problem in Create AD user using Microsoft Graph APIs

193 Views Asked by At

I have to use Microsoft Active Directory APIs to create an active directory account which will then be synced with Azure. I am using Microsoft Graph SDK for PHP to implement the functionality.

  1. Created APP in AD account
  2. Retrieved TenantId, ClientId and Secreat keys.
  3. Using SDK, retrieved access token.
  4. Next called function to create user.

Here I initially got permission related issues. In AD APP, I gave full permission for directory read. In permissions section I could not find any permission option related to Create User. Also in "Microsoft Graph SDK for PHP", while using create user function, I am getting "Class 'User' not found in D:\xampp\htdocs\test\vendor\microsoft\microsoft-graph\src\Http\GraphResponse.php" error.

Here I would like to confirm if this is possible to create an active directory account which will then return license key in response to be used by the newly created user?

Any help would be greatly appreciated.

Many Thanks.

1

There are 1 best solutions below

0
Mehtab Siddique On

The permissions required for creating the user:

enter image description here

The request body for creating the user:

enter image description here

please refer this example:

<?php

// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);

$requestBody = new User();
$requestBody->setAccountEnabled(true);

$requestBody->setDisplayName('Adele Vance');

$requestBody->setMailNickname('AdeleV');

$requestBody->setUserPrincipalName('[email protected]');

$passwordProfile = new PasswordProfile();
$passwordProfile->setForceChangePasswordNextSignIn(true);

$passwordProfile->setPassword('xWwvJ]6NMw+bWH-d');


$requestBody->setPasswordProfile($passwordProfile);


$requestResult = $graphServiceClient->users()->post($requestBody);

Hope this helps.