PHP code example of socialiteproviders / azureadb2c

1. Go to this page and download the library: Download socialiteproviders/azureadb2c 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 / azureadb2c example snippets


'azureadb2c' => [
    'client_id' => env('AADB2C_ClientId'),
    'client_secret' => env('AADB2C_ClientSecret'),
    'redirect' => env('AADB2C_RedirectUri'),
    'domain' => env('AADB2C_Domain'),  // {your_domain}.b2clogin.com
    'policy' => env('AADB2C_Policy'),  // such as 'b2c_1_user_susi'
    'default_algorithm' => env('AADB2C_DefaultAlgorithm', 'RS256'), // decoding algorithm JWK key such as 'RS256'
    'custom_domain' => env('AADB2C_CUSTOM_DOMAIN'), // optional - set to use your custom domain e.g. login.contoso.com
    'tenant' => env('AADB2C_TENANT'), // optional - set to use your tenant ID or custom domain in place of the default onmicrosoft.com one
],

Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
    $event->extendSocialite('azureadb2c', \SocialiteProviders\AzureADB2C\Provider::class);
});

protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \SocialiteProviders\AzureADB2C\AzureADB2CExtendSocialite::class.'@handle',
    ],
];

return Socialite::driver('azureadb2c')->redirect();

$provided_user = Socialite::driver('azureadb2c')->user();

return redirect(Socialite::driver('azureadb2c')->logout('http://localhost'));

    public function setRaw($user)
    {
        $user['name'] = $user['name'] ?: $user['given_name'].' '.$user['family_name'];
        $user['nickname'] = $user['name'] ?: '';
        $user['email'] = $user['emails'][0];

        return parent::setRaw($user);
    }