1. Go to this page and download the library: Download vinhhoang/oauth2-azure 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/ */
vinhhoang / oauth2-azure example snippets
'providers' => [
// Other service providers...
VinhHoang\OAuth2\AzureServiceProvider::class,
],
namespace App\Http\Controllers;
use Azure;
class LoginController
{
public function login()
{
return Azure::redirect();
}
public function handleCallback()
{
$token = Azure::getAccessToken('authorization_code', [
'code' => $_GET['code'],
'resource' => 'https://graph.windows.net',
]);
try {
// We got an access token, let's now get the user's details
$me = Azure::get("me", $token);
} catch (\Exception $e) {
//
}
// Use this to interact with an API on the users behalf
echo $token->getToken();
}
public function logout()
{
$redirect_url = "http://example.com";
return redirect(Azure::getLogoutUrl($redirect_url));
}
}