Install the package:
composer require wika-group/azureadb2c-spa-for-laravel
Publish assets:
php artisan vendor:publish --tag=azureb2cspa-assets
Publish migration:
php artisan vendor:publish --tag=azureb2cspa-migrations
Extend .env and configure:
AADB2C_CLIENT_ID=
AADB2C_DOMAIN= # {your_domain}.b2clogin.com
AADB2C_CUSTOM_DOMAIN= # Optional: set to use custom domain e.g. login.contoso.com
AADB2C_POLICY= # Optional - Default: 'B2C_1_sign-up_and_sign-in_policy'
AADB2C_DEFAULT_ALGORITHM= # Optional: Decoding algorithm JWK key. Default: 'RS256'
AADB2C_OAUTH_COLUMN= # Optional: Name of the OAuth ID column. Default 'oauth_id'
Optional: Publish config:
php artisan vendor:publish --tag=azureb2cspa-config
@azureB2cSpaScripts()
If you use it with Livewire or Wire Extender, you must add @assets
:
@assets
@azureB2cSpaScripts()
@endassets
If you use Wire Extender, you must Enable browser session support.
<button onClick="b2cPopupLogin()">Login with Azure B2C</button>
You can add custom logic by using the emitted events: For succeeded login the following events are emitted:
if (window.Livewire !== undefined) {
window.Livewire.emit("azureB2cLoginSucceeded", data.user)
} else {
dispatchEvent(new CustomEvent("azureB2cLoginSucceeded"))
}
For a failed login the following events are emitted:
if (window.Livewire !== undefined) {
window.Livewire.emit("azureB2cLoginFailed")
} else {
dispatchEvent("azureB2cLoginFailed")
}
You must add the URL of the SPA in the Azure Portal: