PHP client for azure authentication
Just run
composer require steinbauerit/azure-auth-php-client
try {
$clientId = 'clientId';
$clientSecret = 'secret';
$authorizationCode = 'authCode';
$tenantId = 'common';
$redirectUri = 'http://localhost';
// The auth provider will only authorize requests to
// the allowed hosts, in this case Microsoft Graph
$allowedHosts = ['graph.microsoft.com'];
$scopes = ['User.Read'];
$tokenRequestContext = new AuthorizationCodeContext(
$tenantId,
$clientId,
$clientSecret,
$authorizationCode,
$redirectUri
);
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes, $allowedHosts);
$requestAdapter = new GuzzleRequestAdapter($authProvider);
$client = new GraphApiClient($requestAdapter);
$me = $client->me()->get()->wait();
echo "Hello {$me->getDisplayName()}, your ID is {$me->getId()}";
} catch (ApiException $ex) {
echo $ex->getMessage();
}