PHP code example of postiefs / laravel-sso

1. Go to this page and download the library: Download postiefs/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/ */

    

postiefs / laravel-sso example snippets


Route::middleware(['web', 'sso'])->group(...);           // guests go to the portal
Route::middleware(['web', 'auth', 'sso.session'])->...;  // keep your own login, add the portal's rules

use Postiefs\Sso\Facades\Sso;

Sso::active();            // signed in through the portal (false for a local login)
Sso::secondsRemaining();
Sso::hasRole('editor');   // the portal's `admin` role always passes
Sso::groups(); Sso::department();

class AppUserResolver extends \Postiefs\Sso\Support\DefaultUserResolver
{
    protected function isAllowed(Model&Authenticatable $user, SsoIdentity $identity): bool
    {
        return $user->status !== UserStatus::Inactive;   // a refused user sees a 403
    }
}

Event::listen(SsoUserCreated::class, fn ($event) => $event->user->assignRole('Team Member'));

use Postiefs\Sso\Testing\LaunchToken;

$this->get('/sso/callback?sso_token='.LaunchToken::make(['email' => '[email protected]', 'roles' => ['editor']]))
    ->assertRedirect();
bash
php artisan sso:check