girift/apitwist-sso-laravel-client
最新稳定版本:0.2.2
Composer 安装命令:
composer require girift/apitwist-sso-laravel-client
包简介
This is the client Integration with ApiTwist SSO.
关键字:
README 文档
README
Client integration for ApiTwist SSO.
Installation
Install the package via composer:
composer require girift/apitwist-sso-laravel-client
Add SSO config to your .env file:
SSO_CLIENT_ID=client_id SSO_CLIENT_SECRET=client_secret SSO_DOMAIN='https://sso.apitwist.com'
Add HasSsoTokens trait to your User model
// ... use Girift\SSO\Traits\HasSsoTokens; class User extends Authenticatable { use HasSsoTokens; // ... }
Add middlewares to your app/Http/Kernel.php file $routeMiddleware array:
protected $routeMiddleware = [ // ... 'sso.auth' => \Girift\SSO\Http\Middleware\SsoAuthenticate::class, 'sso.api' => \Girift\SSO\Http\Middleware\SsoApiAuthenticate::class, ];
You can publish and run the migrations with:
php artisan vendor:publish --tag="sso-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="sso-config"
This is the contents of the published config file:
return [ 'client_id' => env('SSO_CLIENT_ID'), 'client_secret' => env('SSO_CLIENT_SECRET'), 'redirect_url' => config('app.url') . '/sso/callback', 'sso_domain' => env('SSO_DOMAIN', 'https://sso.apitwist.com'), 'authorize_url' => config('sso.sso_domain').'/oauth/authorize', 'api_url' => config('sso.sso_domain').'/oauth/token', 'logout_url' => config('sso.sso_domain'). '/logout', 'get_user_url' => config('sso.sso_domain'). '/api/user', ];
Usage
Use sso.auth along with web middleware in your routes/web.php file:
Route::middleware([ 'web', 'sso.auth' ])->get('/route', function () { // Your routes });
If you see Session store not set on request. error, add theese middlewares in your app/Http/Kernel.php file $middleware array:
protected $middleware = [ // ... \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, ];
Use named routes as authentication routes:
sso.login sso.logout
Add sso.loggedIn named route to your home page:
Route::middleware([ 'web', 'sso.auth' ])->get('/home', function () { // Your home page })->name('sso.loggedIn')->name('home');
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 785
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-13