PHP code example of tuahweb / php-sso-client-connect

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

    

tuahweb / php-sso-client-connect example snippets


'sso' => [
    'client_id' => env('SSO_CLIENT_ID'),
    'client_secret' => env('SSO_CLIENT_SECRET'),
    'redirect' => env('SSO_REDIRECT_URI', env('APP_URL').'/auth/sso/callback'),
    'webhook_secret' => env('SSO_WEBHOOK_SECRET'),
    'server_url' => env('SSO_PROVIDER'),

    // Endpoint berikut diturunkan dari SSO_PROVIDER.
    // Override via env jika path default tidak sesuai.
    'authorize_url' => env('SSO_AUTHORIZE_URL', rtrim(env('SSO_PROVIDER', 'http://sso-server.test'), '/').'/oauth/authorize'),
    'token_url' => env('SSO_TOKEN_URL', rtrim(env('SSO_PROVIDER', 'http://sso-server.test'), '/').'/oauth/token'),
    'user_info_url' => env('SSO_USER_INFO_URL', rtrim(env('SSO_PROVIDER', 'http://sso-server.test'), '/').'/api/user'),
],

->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'verify.sso.signature' => \Tuahweb\SsoClient\Middleware\VerifySsoSignature::class,
        'check.sso.active' => \Tuahweb\SsoClient\Middleware\CheckSsoActive::class,
    ]);
})

Gate::before(function ($user, $ability) {
    if (method_exists($user, 'hasPermission')) {
        return $user->hasPermission($ability) ?: null;
    }
    return null;
});

'routes' => [
    'auth' => false,    // Disable SSO auth routes
    'webhook' => false, // Disable webhook route
],

// config/sso.php
'routes' => [
    'dashboard_url' => env('SSO_DASHBOARD_URL', 'http://sso-server.test/dashboard'),
],

// config/sso.php
'user_model' => App\Models\YourCustomUser::class,

namespace App\Jobs;

use Tuahweb\SsoClient\Jobs\ProcessSsoWebhookJob;

class CustomProcessSsoWebhookJob extends ProcessSsoWebhookJob
{
    public function handle(): void
    {
        // Custom logic before/after sync
        \Log::info('Processing webhook', ['event' => $this->event]);

        parent::handle();
    }
}

// config/sso.php
'jobs' => [
    'process_webhook' => \App\Jobs\CustomProcessSsoWebhookJob::class,
],

namespace App\Http\Controllers\Auth;

use Tuahweb\SsoClient\Http\Controllers\SsoController as BaseSsoController;

class SsoController extends BaseSsoController
{
    protected function authenticatedRedirect($user): RedirectResponse
    {
        return redirect()->intended('/custom-dashboard');
    }

    protected function loginFailedRedirect(string $message): RedirectResponse
    {
        return redirect()->route('custom.login')
            ->with('error', $message);
    }
}

// config/sso.php
'controllers' => [
    'sso' => \App\Http\Controllers\Auth\SsoController::class,
],
bash
php artisan vendor:publish --tag=sso-client-config
json
"repositories": [
    {
        "type": "path",
        "url": "../packages/tuahweb/php-sso-client-connect"
    }
],
"