gungcahyadipp/sso-client
Composer 安装命令:
composer require gungcahyadipp/sso-client
包简介
A universal SSO Client package for Laravel, API, and PHP Native
README 文档
README
A universal, production-ready SSO client for Laravel (10, 11, 12), Filament, API, and Native PHP applications. Supports both session-based and token-based authentication flows.
📋 Table of Contents
🚀 Features
- Multi-Framework: Support for Laravel 10, 11, and 12.
- Filament Ready: Seamless integration with Filament v3+.
- Dual Mode:
session: For traditional web apps & Filament (Stateful).token: For APIs & SPAs like React/Vue (Stateless).
- PHP Native: Work outside Laravel using cURL.
- Manager Pattern: Extensible driver system.
📦 Installation
Install the package via composer:
composer require gungcahyadipp/sso-client
Publish the configuration (Laravel):
php artisan sso-client:install
Note: During installation, you will be prompted to publish a customizable SSO Controller. Type yes if you want to modify the callback logic.
⚙️ Configuration
Add these to your .env file:
SSO_MODE=session # Use 'session' for Web/Filament, 'token' for API
SSO_BASE_URL=https://sso.yourserver.com
SSO_CLIENT_ID=your-client-id
SSO_CLIENT_SECRET=your-client-secret
SSO_REDIRECT_URI=http://your-app.com/sso/callback
🛠️ Usage Examples
1. Laravel Web (Stateful / Session)
Ideal for standard Laravel blade applications.
Route Protection:
Apply the sso.auth middleware to your routes.
// routes/web.php
Route::middleware(['sso.auth'])->group(function () {
Route::get('/dashboard', function () {
return view('dashboard');
});
});
Automatically Registered Routes: The package provides these routes out of the box:
route('sso.login')->/sso/login(Redirects to SSO Server)route('sso.callback')->/sso/callback(Handles authentication)route('sso.logout')->/sso/logout(POST)
Adding the SSO Login Button
You can add a simple link or button in your login page (Blade):
<!-- Simple Link -->
<a href="{{ route('sso.login') }}" class="btn btn-primary">
Login with SSO
</a>
<!-- Or using a form for better security/styling -->
<form action="{{ route('sso.login') }}" method="GET">
<button type="submit" class="btn-sso">
Sign in with Account SSO
</button>
</form>
Custom Login Logic:
The package provides /sso/login and /sso/callback routes out of the box.
2. Laravel Filament (v3/v4/v5)
Since Filament uses Laravel's default guard, it works automatically.
Setup:
- Set
SSO_MODE=session. - Apply
sso.authmiddleware in your Panel Provider:
// app/Providers/Filament/AdminPanelProvider.php
public function panel(Panel $panel): Panel
{
return $panel
->authMiddleware([
\GungCahyadiPP\SSOClient\Http\Middleware\AuthenticateSSO::class,
]);
}
3. Laravel API (Stateless / Token)
For separate React/Vue frontends.
Config:
SSO_MODE=token
Workflow:
Frontend redirects to SSO server, gets code, then sends it to your API.
// Your API Controller
use GungCahyadiPP\SSOClient\Facades\SSOClient;
public function authenticate(Request $request) {
$result = SSOClient::handleCallback($request->code);
// Returns structured JSON for frontend:
// { "status": "success", "access_token": "...", "user": { ... } }
return response()->json($result);
}
4. PHP Native (Without Laravel)
Use the standalone client in any PHP project.
require 'vendor/autoload.php';
use GungCahyadiPP\SSOClient\Native\SSONativeClient;
$config = [
'base_url' => 'https://sso.server.com',
'client_id' => '...',
'client_secret' => '...',
'redirect_uri' => '...',
'endpoints' => [
'authorize' => '/oauth/authorize',
'token' => '/oauth/token',
'user' => '/api/v1/me',
]
];
$client = new SSONativeClient($config);
// 1. Get Redirect URL
$url = $client->getRedirectUrl();
header("Location: $url");
// 2. In your callback script:
$token = $client->getToken($_GET['code']);
$user = $client->getUser($token['access_token']);
print_r($user);
🎨 Customization
If you need to customize the login or callback logic (e.g., adding custom role checks or data synchronization), publish the SSO controller:
php artisan vendor:publish --tag=sso-controller
This will create app/Http/Controllers/Auth/SSOController.php.
Logic Branching
The stub controller handles different modes automatically:
handleSessionCallback(): Logic for Laravel Web/Filament.- Call
SSOClient::loginUser($user)to authenticate.
- Call
handleTokenCallback(): Logic for API/React.- Returns a structured JSON response for your frontend.
Update your config/sso-client.php to use the new controller:
'controller' => \App\Http\Controllers\Auth\SSOController::class,
🏗️ Clean Architecture
This package uses the Manager Pattern. You can extend it by adding your own drivers in the Drivers/ directory and registering them in the SSOManager.
🔒 Security
If you discover any security-related issues, please email gungcahyadipp@gmail.com instead of using the issue tracker.
📄 License
The MIT License (MIT). Please see License File for more information.
gungcahyadipp/sso-client 适用场景与选型建议
gungcahyadipp/sso-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「Authentication」 「oauth」 「SSO」 「laravel」 「filament」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gungcahyadipp/sso-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gungcahyadipp/sso-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gungcahyadipp/sso-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-17