PHP code example of adnanhussainturki / microsoft-api-php
1. Go to this page and download the library: Download adnanhussainturki/microsoft-api-php 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/ */
adnanhussainturki / microsoft-api-php example snippets
// INITIALIZATION
$microsoft = new Auth($tenant, $client_id, $client_secret, $callback, $scopes);
header("location: ". $microsoft->getAuthUrl()); //Redirecting to get access token
// ON CALLBACK
session_start();
use myPHPnotes\Microsoft\Handlers\Session;
$microsoft = new Auth(Session::get("tenant_id"),Session::get("client_id"), Session::get("client_secret"), Session::get("redirect_uri"), Session::get("scopes"));
$tokens = $microsoft->getToken($_REQUEST['code'], Session::get("state"));
// Setting access token to the wrapper
$microsoft->setAccessToken($tokens->access_token);
use myPHPnotes\Microsoft\Models\User;
$user = (new User); // User get pulled only if access token was generated for scope User.Read
echo $user->data->getGivenName(); // Adnan
echo $user->data->getOnPremisesImmutableId(); // [email protected]
// ON CALLBACK
session_start();
use myPHPnotes\Microsoft\Handlers\Session;
$microsoft = new Auth(Session::get("tenant_id"),Session::get("client_id"), Session::get("client_secret"), Session::get("redirect_uri"), Session::get("scopes"));
$tokens = $microsoft->getToken($_REQUEST['code'], Session::get("state"));
$refreshToken = $tokens->refresh_token;
$refreshToken = "M.R3_BAY.CbCa*dfsafayrRe9NFNcFEWJBZF9*sXaIYH1HHEFb6i2uUFCGT0KvyXzXulrjPqC3qRgw*NAuajBICU6PmdvfHOyeWGdmE8tUZ4f6XSluF3aKHBGbs*FGSvY7nkUgHhJ*F*4Pfg6SLuNNHY8mh6U8pMNuY1EwnKgAI9s1X4Tt0VXm*mIeLoiw8MTifTukr1aK!7rQOA18ow84bOSpPyu7lZbwATC2pygflRZEOPiHi2!MGrw6CuCxLPgGVu88rsWZJJw3rLjSTofJF78Sgb8ZjkIJAwcfZukotN0lF0GaTThWvM35QEricRyVBYxIC*8iXywFmqKkeClJFeVYx!US35inDel3oXg9**jtd8FAN7x!050JGWN7iJgJA!eMg4h1L6PjcmCZfuVnv0s5eGJ3jauimRBPKJLT6rgzVvkAtI5mJitumZzKnzQNRCxn03w$$";
$microsoft = new Auth(Session::get("tenant_id"),Session::get("client_id"), Session::get("client_secret"), Session::get("redirect_uri"), Session::get("scopes"));
$microsoft->setRefreshToken($refreshToken);
$accessToken = $auth->setAccessToken();
$user = (new User); // User get pulled only if refresh token was generated for scope User.Read
echo $user->data->getGivenName(); // Adnan
echo $user->data->getOnPremisesImmutableId(); // [email protected]