mishal/jwt
Lightweight PHP JSON Web Token (JWT) library with support for None, HS256 (HMAC SHA-256), and RS256 (RSA SHA-256). Simple encode/decode API with allowed-algorithm validation and support for standard reserved claims like exp, nbf, iss, and aud.
ES256, PS256, or HS384/512).HS256/RS256 (modern apps may need ES256 or asymmetric key rotation).Authenticatable traits).jti tracking for revocation).JwtGuard for auth).psalm or phpstan to audit for deprecated PHP features.RS256 tokens?Auth system (e.g., auth:api middleware)?RS256 vs. HS256 in high-throughput APIs?firebase/php-jwt (active, Laravel-friendly) or spomky-labs/token?laravel/sanctum, no built-in token persistence.Phase 1: Pilot Integration
/api/v1/auth/login).Auth::attempt() with JWT issuance on login.Authorization: Bearer headers.laravel-debugbar to inspect token payloads.Phase 2: Full Auth Overhaul
Illuminate\Auth\Guard to support JWT.session:table) to JWT.Phase 3: Advanced Features
jti claims and a revocation table (e.g., revoked_tokens).composer require php:^7.4 to avoid PHP 8.x issues.openssl for RS256 (common on shared hosting).| Step | Priority | Dependencies | Tools/Notes |
|---|---|---|---|
| Set up JWT issuer | P0 | mishal/jwt |
Use HS256 for testing. |
| Create middleware | P0 | Laravel middleware stack | Extend Illuminate\Auth\Middleware. |
| Test auth flow | P0 | Postman/Newman | Validate exp, iss, aud claims. |
| Implement refresh | P1 | Custom logic | Store refresh tokens in DB. |
| Add revocation | P1 | Database migration | Track jti in revoked_tokens. |
| RBAC integration | P2 | Laravel Policies | Use verify option for claims. |
Jwt::decode() with debug: true (if extended).VerificationException details for troubleshooting.leeway for exp/nbf claims.HS256 secrets and RS256 keys.k6 or artillery to simulate 10K RPS and measure JWT validation time.RS256 (e.g., Redis with 1-hour TTL).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Token leakage | Unauthorized access | Short-lived tokens + revocation list. |
| Key compromise (HS256) | Token forgery | Rotate secrets; monitor for abuse. |
| Clock desync (exp/nbf) | False rejections/acceptances | Configure leeway (e.g., 5 minutes). |
| Database outage (revocation) | Revoked tokens not blocked | Fallback to short token TTL. |
| PHP/Openssl upgrade | Package breaks | Test in staging; fork if needed. |
How can I help you explore Laravel packages today?