Downloads
Stars
Version
Install with composer
composer require plokko/laravel-msgraph
Laravel >=5.5 should auto discover and register the required services.
If you have laravel <5.5 you need to manually register the provider in your /config/app.php
<?php
//...
'providers' => [
//...
plokko\MsGraph\MsGraphServiceProvider::class,
//...
],
//...
MSGRAPH_TENANT=<YOUR-TENANT-ID>
MSGRAPH_CLIENT_ID=<YOUR-CLIENT-ID>
MSGRAPH_CLIENT_SECRET=<YOUR-CLIENT-SECRET>
MSGRAPH_REDIRECT_URI=<YOUR-URL-CALLBACK>
You can get information about an user by id
$user = MsGraph::User()->find("USER-ID");
/**@var \Microsoft\Graph\Model\User $user**/
or by principal name
$user = MsGraph::User()->findByPrincipalName("[email protected]");
$userQuery = MsGraph::User()->list();
$userQuery
->take(5)//limit to 5
->search('displayName:Test')//Search
->orderBy('displayName')//Order
->select(['id','displayName'])//Select fields
;
$users = $userList->get(); // Execute the query
/**@var \Microsoft\Graph\Model\User[] $users**/
You can count the users like the list users
$userQuery = MsGraph::User()->list();
$userQuery
->search('displayName:Test')
;
$count = $userList->count(); // Execute the query
/**@var int $count**/
// Prepare your user data as a Microsoft\Graph\Model\User object or as an Array of key-values
$userData = new \Microsoft\Graph\Model\User([
"mailNickname" => 'UserName',
"displayName" => "User Name",
"givenName" => "User",
"surname" => "Name",
"password" => "TheUserPassword123",
"jobTitle" => null,
"mail" => "[email protected]",
"userPrincipalName" => "[email protected]",
"mobilePhone" => null,
"businessPhones" => ['0000 123456'],
"officeLocation" => null,
"preferredLanguage" => null,
]);
// Or
$userData = [
"mailNickname" => 'UserName',
"displayName" => "User Name",
"givenName" => "User",
"surname" => "Name",
"password" => "TheUserPassword123",
"jobTitle" => null,
"mail" => "[email protected]",
"userPrincipalName" => "[email protected]",
"mobilePhone" => null,
"businessPhones" => ['0000 123456'],
"officeLocation" => null,
"preferredLanguage" => null,
];
//...
$password = null; //If set will overwrite user password in data
$accountEnabled = null; // If the account is enabled, if set will overwrite user data, if null and not set in user data it will default to true
$forcePasswordChange = false; // Will force password change on next login (see passwordProfile)
MsGraph::User()->create($userData,$password,$accountEnabled,$forcePasswordChange);
// Prepare your user data as a Microsoft\Graph\Model\User object or as an Array of key-values
// id or userPrincipalName are required to identify the user
// You can fill only the information you want to change
$userData = new \Microsoft\Graph\Model\User([
'id' => 'your-user-id',
"mailNickname" => 'UserName',
]);
// Or
$userData = [
"userPrincipalName" => "[email protected]",
"mailNickname" => 'UserName',
];
//...
MsGraph::User()->update($userData);
User can be deleted by id
MsGraph::User()->delete("USER-ID");
or by principal name
MsGraph::User()->deleteByPrincipalName("[email protected]");