PHP code example of girift / apitwist-sso-laravel-client

1. Go to this page and download the library: Download girift/apitwist-sso-laravel-client 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/ */

    

girift / apitwist-sso-laravel-client example snippets


SSO_CLIENT_ID=client_id
SSO_CLIENT_SECRET=client_secret
SSO_DOMAIN='https://sso.apitwist.com'

// ...
use Girift\SSO\Traits\HasSsoTokens;

class User extends Authenticatable
{
    use HasSsoTokens;
    // ...
}

protected $routeMiddleware = [
    // ...
    'sso.auth' => \Girift\SSO\Http\Middleware\SsoAuthenticate::class,
    'sso.api' => \Girift\SSO\Http\Middleware\SsoApiAuthenticate::class,
];

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',
];

Route::middleware([ 'web', 'sso.auth' ])->get('/route', function () {
    // Your routes
});

protected $middleware = [
    // ...
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
];

sso.login
sso.logout

Route::middleware([ 'web', 'sso.auth' ])->get('/home', function () {
    // Your home page
})->name('sso.loggedIn')->name('home');
bash
php artisan vendor:publish --tag="sso-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="sso-config"