lsmith77 / AzureADB2C

[READ ONLY] Subtree split of the SocialiteProviders/AzureADB2C Provider (see SocialiteProviders/Providers)

Home Page:https://socialiteproviders.com/AzureADB2C/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Azure AD B2C

composer require socialiteproviders/azureadb2c

Installation & Basic Usage

Please see the Base Installation Guide, then follow the provider specific instructions below.

Add configuration to config/services.php

'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'
],

Add provider event listener

Configure the package's listener to listen for SocialiteWasCalled events.

Add the event to your listen[] array in app/Providers/EventServiceProvider. See the Base Installation Guide for detailed instructions.

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

Usage

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

Redirect to Azure AD B2C

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

Callback

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

Logout

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

Returned User fields

  • sub
  • name

Note) If you want to add claim mappings, change User::setRaw() function. The claims mappings must be match with claims in id_token which Azure AD B2C returns.

    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);
    }

About

[READ ONLY] Subtree split of the SocialiteProviders/AzureADB2C Provider (see SocialiteProviders/Providers)

https://socialiteproviders.com/AzureADB2C/


Languages

Language:PHP 100.0%