keenops / auth-client
OAuth2 SSO client SDK for integrating Laravel applications with the Central Authentication Server
v1.0.0
2026-03-07 17:57 UTC
Requires
- php: ^8.4
- guzzlehttp/guzzle: ^7.0
- illuminate/auth: ^12.0
- illuminate/http: ^12.0
- illuminate/routing: ^12.0
- illuminate/support: ^12.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.0
- phpunit/phpunit: ^11.0
README
OAuth2 SSO client SDK for integrating Laravel applications with the Central Authentication Server.
Installation
Install via Composer:
composer require keenops/auth-client
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=auth-client-config
Add the following environment variables to your .env file:
AUTH_SERVER_URL=https://your-auth-server.com AUTH_CLIENT_ID=your-client-id AUTH_CLIENT_SECRET=your-client-secret AUTH_REDIRECT_URI=https://your-app.com/auth/callback AUTH_SCOPES=read-user AUTH_BACKCHANNEL_LOGOUT_SECRET=your-backchannel-secret
Usage
SSO Authentication
The package automatically registers the following routes:
GET /auth/redirect- Redirect to auth server for loginGET /auth/callback- Handle callback from auth serverPOST /auth/logout- Logout and revoke tokenPOST /auth/backchannel-logout- Backchannel logout webhook
Protecting Routes
Use the provided middleware to protect routes:
// Require authentication Route::middleware('auth.server')->group(function () { Route::get('/dashboard', DashboardController::class); }); // Require specific permissions Route::middleware(['auth.server', 'server.permission:manage_users'])->group(function () { Route::get('/admin/users', UserController::class); });
Accessing the Authenticated User
use Illuminate\Support\Facades\Auth; $user = Auth::guard('auth-server')->user(); // Check roles if ($user->hasRole('admin')) { // ... } // Check permissions if ($user->hasPermission('create_post')) { // ... }
License
The MIT License (MIT). Please see License File for more information.