2017-25 © Pedro Peláez
 

library laravel-sso

image

cblink/laravel-sso

  • Monday, July 16, 2018
  • by hanson
  • Repository
  • 2 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

laravel-sso

install

composer require cblink/laravel-sso -vvv, (*1)

configure

publish config.php and migration

php artisan vendor:publish --provider="Cblink\Sso\SsoServiceProvider", (*2)

migrate:

php artisan migrate, (*3)

this command will create a table name sso to authorize., (*4)

create sso route:

php artisan sso:route, (*5)

also you can create sso through command

php artisan sso:create, (*6)

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, (*7)


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:, (*8)

Route::group(['middleware' => ['ticket', 'auth'], function () {
    // ...
});

The Versions

16/07 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Development Requires

by Avatar hanson