wika-group/azureadb2c-spa-for-laravel
最新稳定版本:1.0.2
Composer 安装命令:
composer require wika-group/azureadb2c-spa-for-laravel
包简介
Use Azure AD B2C single sign-on for Laravel single-page applications
README 文档
README
This composer package provides the necessary logic to handle Azure B2C logins with MSAL in the front end (with a pop-up) and back-end validation. It requires Livewire.
Installation
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_TENANT_ID= 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
Usage
Add scripts to your views
<!-- In main livewire component --> <livewire:azureB2cSpaScripts/>
In order to trigger a Livewire re-render, an event listener is required.
Therefore, the provided trait can be used inside the main Livewire component.
use \WikaGroup\AzureAdB2cSpa\Traits\LoginLogoutEvents;
If you use Wire Extender, you must Enable browser session support.
Add a button to trigger login or logout
@auth
<button onClick="b2cLogout()">Logout</button>
@endauth
@guest
<button onClick="b2cPopupLogin()">Login with Azure B2C</button>
@endguest
Hook into the events
You can add custom logic by using the emitted events for login and logout:
#[On('azureb2c-login-succeeded')] public function azureB2cLoginSucceeded(array $user) {} #[On('azureb2c-login-failed')] public function azureB2cLoginFailed(string $msg) {} #[On('azureb2c-logout-succeeded')] public function azureB2cLogoutSucceeded() {} #[On('azureb2c-logout-failed')] public function azureB2cLogoutFailed(string $msg) {}
Configure Azure B2C
You must add the URL of the SPA in the Azure Portal:
统计信息
- 总下载量: 204
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-13
