quvel/auth
Composer 安装命令:
composer require quvel/auth
包简介
Authentication support for the Quvel framework - handles login, logout, registration, email verification, and OAuth
README 文档
README
API-first authentication package that extends Laravel Fortify with JSON responses, OAuth support, and enhanced features. Uses Fortify 1:1 with minimal overrides via container bindings.
Philosophy
This package wraps Laravel Fortify with quality-of-life improvements:
- API-First Responses - Returns JSON with user data instead of redirects
- OAuth/Socialite Integration - Social login with secure nonce-based flow
- Zero Configuration - Auto-discovers and binds overrides via service provider
- Fortify Compatible - Use standard
config/fortify.phpto enable/disable features
Installation
1. Install Fortify and Sanctum
composer require laravel/fortify laravel/sanctum laravel/socialite php artisan fortify:install php artisan sanctum:install php artisan migrate
2. Install Quvel Auth
composer require quvel/auth
That's it. The package auto-discovers and registers its service provider.
3. Configure Fortify
Edit config/fortify.php:
'prefix' => 'auth', // Routes at /auth/* 'views' => false, // API-only mode 'features' => [ Features::registration(), Features::resetPasswords(), // Features::emailVerification(), Features::updateProfileInformation(), Features::updatePasswords(), Features::twoFactorAuthentication([ 'confirm' => true, 'confirmPassword' => true, ]), ],
4. Publish Migrations (Optional)
php artisan vendor:publish --tag=quvel-auth-migrations php artisan migrate
How It Works
Quvel Auth uses Laravel's container to override Fortify's default implementations:
// Our AuthServiceProvider automatically binds these: // Fortify uses our custom CreateNewUser action $app->singleton(CreatesNewUsers::class, CreateNewUser::class); // Fortify uses our JSON LoginResponse instead of redirects $app->singleton(LoginResponseContract::class, LoginResponse::class); // etc.
When Fortify's controllers run, they resolve these contracts from the container and get our implementations. No route overrides needed.
Routes
Fortify provides core routes (login, register), we provide the rest:
# Fortify Routes (using our container bindings)
POST /auth/login → JSON with user data
POST /auth/register → JSON with user data
# Our Custom Routes
GET /auth/session → Current session info
POST /auth/logout → Logout response
# Password Management
POST /auth/forgot-password
POST /auth/reset-password
# Two-Factor Authentication
POST /auth/two-factor-challenge
POST /auth/user/two-factor-authentication → Enable 2FA
DELETE /auth/user/two-factor-authentication → Disable 2FA
GET /auth/user/two-factor-qr-code
GET /auth/user/two-factor-recovery-codes
POST /auth/user/two-factor-recovery-codes → Regenerate codes
# Profile Management
PUT /auth/user/profile-information
PUT /auth/user/password
# OAuth (Socialite)
GET /auth/provider/{provider}/redirect
GET /auth/provider/{provider}/callback
POST /auth/provider/{provider}/create-nonce
POST /auth/provider/{provider}/redeem-nonce
API Responses
All responses are JSON with consistent structure:
Login Success (no 2FA):
{
"message": "Login successful",
"user": { "id": 1, "name": "...", "email": "..." },
"two_factor": false
}
Login Requires 2FA:
{
"message": "Two-factor authentication required",
"two_factor": true
}
Registration:
{
"message": "Registration successful",
"user": { "id": 1, "name": "...", "email": "..." }
}
Configuration
Fortify Features
Enable/disable features in config/fortify.php:
'features' => [ Features::registration(), // POST /auth/register Features::resetPasswords(), // POST /auth/forgot-password, etc. Features::emailVerification(), // Email verification routes Features::updateProfileInformation(), // PUT /auth/user/profile-information Features::updatePasswords(), // PUT /auth/user/password Features::twoFactorAuthentication(), // All 2FA routes ],
Socialite (OAuth)
Configure providers in config/services.php:
'google' => [ 'client_id' => env('GOOGLE_CLIENT_ID'), 'client_secret' => env('GOOGLE_CLIENT_SECRET'), 'redirect' => env('GOOGLE_REDIRECT_URI'), ],
Disable OAuth in config/quvel-auth.php:
'socialite' => [ 'enabled' => false, ],
Rate Limiting
Automatically configured (5 requests/minute for login and 2FA). Override in your AppServiceProvider if needed:
use Illuminate\Support\Facades\RateLimiter; RateLimiter::for('login', fn ($request) => Limit::perMinute(10)->by($request->email . $request->ip()) );
Customization
Override Response Classes
Create your own response:
// app/Http/Responses/CustomLoginResponse.php class CustomLoginResponse implements LoginResponseContract { public function toResponse($request): JsonResponse { return response()->json([ 'user' => $request->user()->load('roles'), 'permissions' => $request->user()->getAllPermissions(), ]); } }
Bind in your AppServiceProvider:
$this->app->singleton( \Laravel\Fortify\Contracts\LoginResponse::class, \App\Http\Responses\CustomLoginResponse::class );
Override Actions
Same pattern for actions:
$this->app->singleton( \Laravel\Fortify\Contracts\CreatesNewUsers::class, \App\Actions\Fortify\CreateNewUser::class );
Advanced: Publish Routes
For full route customization:
php artisan vendor:publish --tag=quvel-auth-routes
Then disable package routes in config/quvel-auth.php:
'routes' => [ 'enabled' => false, ],
Troubleshooting
Routes not showing?
php artisan route:list --path=auth
Check that Fortify features are enabled and views => false.
Rate limiter errors? Clear config cache:
php artisan config:clear
Need to customize?
Check AuthServiceProvider@registerFortifyOverrides() to see all container bindings.
License
MIT
quvel/auth 适用场景与选型建议
quvel/auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「oauth」 「laravel」 「sanctum」 「fortify」 「quvel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 quvel/auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 quvel/auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 quvel/auth 相关的其它包
同方向 / 同关键字的高下载量 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.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-21