1. Go to this page and download the library: Download sengheat/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/ */
use SengHeat\LaravelSso\Traits\HasSSOProfile;
class User extends Authenticatable
{
use HasSSOProfile;
protected $connection = 'auth_db';
protected $fillable = [
'name', 'email', 'api_token',
'sso_provider', 'sso_provider_id', 'sso_avatar',
];
}
use SengHeat\LaravelSso\Http\Middleware\EnsureSSOUser;
use SengHeat\LaravelSso\Http\Middleware\CacheSsoToken;
->withMiddleware(function (Middleware $middleware) {
$middleware->alias([
'sso.only' => EnsureSSOUser::class,
'sso.cache' => CacheSsoToken::class,
]);
})
// sso.cache runs first — loads user from Redis or auth_db
// auth:sso runs second — user already set, no DB query
Route::middleware(['sso.cache:sso', 'auth:sso'])->group(function () {
Route::apiResource('orders', OrderController::class);
});
$user->isSSOUser(); // true if logged in via OAuth provider
$user->usesProvider('google'); // true | false
$user->ssoAvatar('/default.png'); // avatar URL with fallback
$user->generateApiToken(); // generates token, stores SHA256 hash, returns plain
$user->revokeApiToken(); // sets api_token = null (logout)
User::fromProvider('google')->get(); // query scope
User::nativeUsers()->get(); // users without OAuth
bash
php artisan migrate
sql
-- Create restricted read-only user per service
CREATE USER order_svc WITH PASSWORD 'secret';
GRANT CONNECT ON DATABASE auth_service TO order_svc;
GRANT USAGE ON SCHEMA public TO order_svc;
GRANT SELECT ON TABLE public.users TO order_svc;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.