PHP code example of socialiteproviders / microsoft-azure
1. Go to this page and download the library: Download socialiteproviders/microsoft-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/ */
socialiteproviders / microsoft-azure example snippets
'azure' => [
'client_id' => env('AZURE_CLIENT_ID'),
'client_secret' => env('AZURE_CLIENT_SECRET'),
'redirect' => env('AZURE_REDIRECT_URI'),
'tenant' => env('AZURE_TENANT_ID'),
'proxy' => env('PROXY'), // optionally
'graph_url' => env('AZURE_GRAPH_URL'), // optionally, defaults to https://graph.microsoft.com/v1.0/me; only set to trusted endpoints because access tokens are sent here, especially when using mocks
],
public function logout(Request $request)
{
Auth::guard()->logout();
$request->session()->flush();
$azureLogoutUrl = Socialite::driver('azure')->getLogoutUrl(route('login'));
return redirect($azureLogoutUrl);
}
/**
* Returns a custom config for this specific Azure AD connection / directory
* @return \SocialiteProviders\Manager\Config
*/
function getConfig(): \SocialiteProviders\Manager\Config
{
return new \SocialiteProviders\Manager\Config(
env('AD_CLIENT_ID', 'some-client-id'), // a different clientID for this separate Azure directory
env('AD_CLIENT_SECRET'), // a different secret for this separate Azure directory
url(env('AD_REDIRECT_PATH', '/azuread/callback')), // the redirect path i.e. a different callback to the other azureAD callbacks
['tenant' => env('AD_TENANT_ID', 'common')], // this could be something special if need be, but can also be left out entirely
);
}
//....//
Socialite::driver('azure')
->setConfig(getConfig())
->redirect();