amranibrahem/laravel-jwt-setup
Composer 安装命令:
composer require amranibrahem/laravel-jwt-setup
包简介
Automatically install and configure JWT authentication for Laravel with a single command - complete setup with controllers, requests, responses, and routes
关键字:
README 文档
README
🚀 Automated JWT Authentication Setup for Laravel Applications
A powerful Laravel package that automatically installs and configures JWT authentication with a single command, saving you hours of manual setup.
✨ Features
- ✅ One-command installation - Complete JWT setup with
php artisan jwt:auto-setup - ✅ Automatic package installation - Installs
tymon/jwt-authvia Composer - ✅ Smart configuration - Auto-configures auth guards and JWT settings
- ✅ Model enhancement - Updates User model with JWTSubject implementation
- ✅ Complete file generation - Creates controllers, requests, responses, and routes
- ✅ Professional code structure - Follows Laravel best practices
- ✅ Error handling - Comprehensive error reporting and rollback
- ✅ Validation integration - Custom form requests with validation
- ✅ Standardized responses - Consistent JSON response format
🚀 Installation
You can install the package via Composer:
composer require amranibrahem/jwt-setup
📖 Usage
Run the auto-setup command:
php artisan jwt:auto-setup
What This Command Does:
📦 Installs tymon/jwt-auth package
Automatically installs the required JWT package via Composer
📁 Publishes JWT configuration files
Publishes all necessary configuration files for JWT setup
🔑 Generates JWT secret key
Creates a secure JWT secret key for token signing
⚙️ Updates auth configuration
Automatically configures auth guards in config/auth.php
👤 Enhances User model with JWT methods
Updates the User model to implement JWTSubject interface
🛠 Creates professional file structure:
• Response class - Standardized JSON response format
• Form requests - Register & Login validation classes
• AuthController - Complete authentication logic
• API routes - Ready-to-use authentication endpoints
🎯 Generated File Structure
app/
├── Http/
│ ├── Controllers/
│ │ └── AuthController.php
│ ├── Requests/
│ │ └── Auth/
│ │ ├── LoginRequest.php
│ │ └── RegisterRequest.php
│ └── Responses/
│ └── Response.php
└── Models/
└── User.php (updated)
🔌 API Endpoints
After setup, you'll have these ready-to-use endpoints:
Public Routes
POST /api/auth/register- User registrationPOST /api/auth/login- User login
Protected Routes (Require JWT)
POST /api/auth/logout- User logoutPOST /api/auth/refresh- Refresh JWT token
🎨 Code Examples
Generated AuthController Methods
// Registration public function register(RegisterRequest $request) { // Handles user registration with validation // Returns: User data + JWT token } // Login public function login(LoginRequest $request) { // Handles user authentication // Returns: User data + JWT token } // Logout public function logout(Request $request) { // Invalidates JWT token // Returns: Success message }
Professional Response Format
{
"message": "Login successful",
"data": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2023-01-01 12:00:00"
},
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}
Enhanced User Model
<?php namespace App\Models; use Tymon\JWTAuth\Contracts\JWTSubject; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements JWTSubject { // ... existing code ... /** * Get the identifier that will be stored in the subject claim of the JWT. */ public function getJWTIdentifier() { return $this->getKey(); } /** * Return a key value array, containing any custom claims to be added to the JWT. */ public function getJWTCustomClaims() { return []; } }
⚙️ Configuration
Manual Configuration (If Needed)
After running the setup, you can customize:
- JWT Configuration -
config/jwt.php - Auth Guards -
config/auth.php - Token Expiry - Modify in JWT config
- Response Format - Edit
App\Http\Responses\Response
Environment Variables
Add to your .env file:
JWT_SECRET=your_generated_secret_here
🔒 Security Features
- ✅ Password hashing with bcrypt
- ✅ JWT token expiration
- ✅ Input validation with form requests
- ✅ Protected logout and refresh endpoints
- ✅ Token invalidation on logout
🛠 Troubleshooting
Common Issues & Solutions
-
"Class JWTSubject not found"
- Run:
composer dump-autoload
- Run:
-
"Auth guard [api] is not defined"
- Check
config/auth.phpwas updated correctly
- Check
-
Token not working
- Verify JWT secret:
php artisan jwt:secret
- Verify JWT secret:
-
Routes not found
- Ensure routes are added to
routes/api.php
- Ensure routes are added to
⚡ Comparison with Manual Setup
| Feature | Manual Setup | This Package |
|---|---|---|
| Time Required | 30-60 minutes | 30 seconds |
| Configuration | Manual editing | Automatic |
| Error Handling | Manual debugging | Built-in |
| Code Quality | Variable | Consistent & Professional |
| Best Practices | Research required | Pre-implemented |
| File Structure | Manual creation | Auto-generated |
🎯 Use Cases
- 🚀 Rapid Prototyping - Get JWT auth running in seconds
- 🏢 Enterprise Projects - Standardized authentication setup
- 👥 Team Projects - Consistent codebase across developers
- 📚 Learning Laravel - See professional JWT implementation
- ⚡ API Development - Ready-to-use authentication system
🔄 Migration
After setup, run database migrations:
php artisan migrate
🐛 Reporting Issues
If you encounter any issues, please report them on the GitHub issue tracker.
🏆 Credits
- Amran iBrahem
- Built on tymon/jwt-auth
💡 Why Use This Package?
- ⏱️ Save Time - 30 seconds vs 30+ minutes manual setup
- 🔧 Zero Configuration - Works out of the box
- 📈 Production Ready - Professional code quality
- 🛡️ Secure - Follows security best practices
- 🔍 Debuggable - Comprehensive error messages
- 🔄 Consistent - Same structure across all projects
🔗 Links
⭐ Star us on GitHub if this package saved you time!
🚀 Happy coding with secure JWT authentication!
amranibrahem/laravel-jwt-setup 适用场景与选型建议
amranibrahem/laravel-jwt-setup 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「api」 「Authentication」 「auth」 「laravel」 「token」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 amranibrahem/laravel-jwt-setup 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amranibrahem/laravel-jwt-setup 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 amranibrahem/laravel-jwt-setup 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
Provide a way to secure accesses to all routes of an symfony application.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
A PSR-7 compatible library for making CRUD API endpoints
It's a barebone security class written on PHP
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-23