PHP code example of cblink / laravel-sso
1. Go to this page and download the library: Download cblink/laravel-sso library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cblink / laravel-sso example snippets
'guards' => [
'sso' => [
'driver' => 'session',
'provider' => 'sso',
],
],
'providers' => [
'sso' => [
'driver' => 'sso',
'table' => 'sso',
],
],
// 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);
}
});
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,
];
Route::group(['middleware' => ['ticket', 'auth'], function () {
// ...
});