nixilla/php-jwt
Lightweight PHP JWT library for creating and validating JSON Web Tokens. Sign and verify tokens with common algorithms, manage claims (exp/iat/nbf), and handle key/secret configuration. Suitable for simple auth and API token workflows.
Pros:
firebase/php-jwt, a widely adopted package) integrates seamlessly with Laravel’s built-in HTTP middleware and guard systems.Cons:
tymon/jwt-auth or laravel/sanctum, this package requires manual integration with Laravel’s auth system (e.g., Auth::guard(), Illuminate\Auth\Events).auth:logout) won’t work out-of-the-box. Requires custom logic (e.g., Redis blacklist).VerifyJWTToken).sub, roles) to match Laravel’s User model attributes.Auth::guard('api') to use JWT validation instead of session cookies.throttle, rate-limiting) for API endpoints.createToken($user) helper).SameSite cookie attributes or CORS misconfigurations can lead to XSS/CSRF vulnerabilities.firebase/php-jwt v6.x).libsodium; verify server support (e.g., Docker/PaaS configurations)..env, AWS KMS, or a secrets manager? How will rotation be automated?SessionGuard with a custom JWTGuard extending Illuminate\Auth\GuardHelpers.Illuminate\Auth\Middleware\Authenticate with a JWTAuthenticate subclass.JWTGenerated, JWTInvalid, etc., to trigger analytics or logging.firebase/php-jwt (or fork), symfony/http-foundation (for request parsing).league/oauth2-server (if extending to OAuth2), spatie/laravel-activitylog (for token auditing).tymon/jwt-auth: More Laravel-native but heavier (~500 stars).laravel/sanctum: Better for SPAs but session-based under the hood.firebase/php-jwt to composer.json.JWTService with generate(), validate() methods.GET /api/user).Auth::guard('api') with JWT validation in app/Http/Kernel.php.Auth::attempt() → JWTService::generate()).jwt:rotate Artisan command)./login endpoints.HasApiTokens trait for user associations.openssl (required for RS256), libsodium (optional but recommended for RS256).failed_jwt_attempts (for brute-force protection).refresh_tokens (if implementing refresh logic).| Step | Task | Dependencies | Tools |
|---|---|---|---|
| 1 | Install firebase/php-jwt |
Composer | composer require firebase/php-jwt |
| 2 | Create JWTService class |
- | PHPUnit, Pest |
| 3 | Add JWT middleware | JWTService |
php artisan make:middleware VerifyJWT |
| 4 | Replace Auth::guard() |
Middleware | config/auth.php |
| 5 | Implement token refresh | Redis | predis/predis |
| 6 | Add revocation logic | Redis | laravel-redis |
| 7 | Test with Postman/cURL | All above | php artisan test |
| 8 | Deploy to staging | - | GitHub Actions, Docker |
README-KEY-ROTATION.md).composer update).TokenExpiredException: Check token TTL and server clock sync.SignatureInvalid: Verify keys and algorithm consistency.dd($request->bearerToken()) for inspection.docs/auth/jwt.md (setup, claims, algorithms).docs/troubleshooting.md (time skew, key errors).k6 or wrk).Redis::remember()).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Key Compromise | Unauthorized access | Rotate keys immediately; log |
How can I help you explore Laravel packages today?