cblink/laravel-sso
最新稳定版本:1.0.1
Composer 安装命令:
composer require cblink/laravel-sso
包简介
README 文档
README
install
composer require cblink/laravel-sso -vvv
configure
publish config.php and migration
php artisan vendor:publish --provider="Cblink\Sso\SsoServiceProvider"
migrate:
php artisan migrate
this command will create a table name sso to authorize.
create sso route:
php artisan sso:route
also you can create sso through command
php artisan sso:create
add to your auth.php:
'guards' => [ 'sso' => [ 'driver' => 'session', 'provider' => 'sso', ], ], 'providers' => [ 'sso' => [ 'driver' => 'sso', 'table' => 'sso', ], ],
usage
Get ticket in client
// sso client system Route::get('sso', function () { $client = new \GuzzleHttp\Client(); $response = $client->get('http://yourdomain/sso/getTicket?'.http_build_query([ 'app_id' => 'your_app_id', 'secret' => 'your_secret', ])); $result = json_decode((string)$response->getBody(), true); if ($ticket = $result['ticket'] ?? null) { return redirect('http://yourdomain/sso/login?ticket='.$ticket); } });
Redirect to any url
add middleware to Http/kernel.php
protected $routeMiddleware = [ // ... 'ticket' => \Cblink\Sso\Http\Middleware\LoginWithTicket::class, ]; // declare route priority protected $middlewarePriority = [ \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \Cblink\Sso\Http\Middleware\LoginWithTicket::class, \Illuminate\Auth\Middleware\Authenticate::class, \Illuminate\Session\Middleware\AuthenticateSession::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Auth\Middleware\Authorize::class, ];
in web.php , add ticket before auth:
Route::group(['middleware' => ['ticket', 'auth'], function () { // ... });
统计信息
- 总下载量: 1.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 123
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-16