1. Go to this page and download the library: Download joeystowe/ms-graph-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joeystowe / ms-graph-api example snippets
Route::get('/', function () {
return view('welcome');
})->middleware('ms-auth');
// Returns an object with the following properties set
Joeystowe\MsGraphApi\LoggedInUser::user();
{
"id" => "1111-2222-33333-44444" //ms user id
"name" => "John Doe" //Full Name
"email" => "[email protected]"
"principalName" => "[email protected]"
"bannerUsername" => "jdoe"
"token" => "1111-2222-3333-4444" //ms session token
}
//Fetch users properties as an array
Joeystowe\MsGraphApi\LoggedInUser::userArray();
//Fetch users properties as a pre-filled User model
Joeystowe\MsGraphApi\LoggedInUser::userModel();
//Fetch a single user attribute (throws exception is property is not found)
Joeystowe\MsGraphApi\LoggedInUser::userAttribute('principalName')
//returns "[email protected]"
$user = Joeystowe\MsGraphApi\LoggedInUser::user();
//resolve instance of current user API
$graphApi = app(Joeystowe\MsGraphApi\MsGraphCurrentUserApi::class, ['token' => $user->token]);
//Get all user's groups, returns array of groups
$graphApi->groups()
//Check if a user is in a specific group, returns boolean
$graphApi->inGroup(groupId: $groupIdToCheck)