brick/math dependency ensures robust cryptographic operations.web-token/jwt-framework) is framework-agnostic. Laravel’s service container can manually register the core components (e.g., JWTManager, AlgorithmManager) via AppServiceProvider.KeyStorage interfaces).KeyProvider implementations.VerifyJWTMiddleware) or can be used in controllers/services via dependency injection.| Risk Area | Mitigation Strategy |
|---|---|
| Breaking changes (v4.x) | Evaluate migration path from firebase/php-jwt (if used) or ensure greenfield adoption. Use the v3.x to v4.0 migration guide. |
| Cryptographic complexity | Validate key sizes/algorithms against RFC 7518 and use the package’s UsageAnalyzer to detect misconfigurations. |
| Performance overhead | Benchmark JWE operations (e.g., ChaCha20-Poly1305) in production-like loads. Sodium extension (ext-sodium) can improve Base64URL encoding performance. |
| Key rotation | Design a strategy for rotating keys (e.g., KeySet with multiple keys + alg: "RS256" + kid header) and test rollover scenarios. |
| Dependency bloat | Audit brick/math, spomky-labs/pki-framework, and symfony/http-client-contracts for compatibility with Laravel’s ecosystem (e.g., no conflicts with Guzzle or Symfony’s HTTP components). |
RS256 over HS256) or allow dynamic selection?JWTManager, AlgorithmManager, and key providers as Laravel bindings.HandleIncomingJWT middleware to validate tokens from headers/cookies.Authenticatable or use a custom JWTGuard for token-based auth.laravel/symfony-bundle) or manually adapt the bundle’s configuration to Laravel’s config/ structure.ext-openssl, ext-json (though the latter is optional per #616).ext-sodium (for performance), psr/cache (for key caching), spomky-labs/pki-framework (for advanced key operations).| Current State | Migration Steps |
|---|---|
| No JWT library | 1. Add web-token/jwt-framework to composer.json. 2. Register core services in AppServiceProvider. 3. Implement middleware/guard for auth. |
Using firebase/php-jwt |
1. Replace Firebase\JWT\JWT with WebToken\JWT\JWT. 2. Update algorithms to use AlgorithmManager. 3. Migrate key storage to KeyStorage interfaces. 4. Test all token flows. |
| Custom JWT implementation | 1. Replace manual Base64URL encoding/decoding with Base64UrlSafe. 2. Adopt JWS/JWE classes for signing/encryption. 3. Use UsageAnalyzer to validate security. |
| Symfony app migrating to Laravel | 1. Port Symfony Bundle config to Laravel’s config/jwt.php. 2. Replace Symfony’s security.yaml auth with Laravel’s middleware/guard. 3. Test with php artisan jwt:test (if available). |
exp, nbf, iss, aud) and custom claims.Auth::guard('jwt')).nbf/exp).composer require web-token/jwt-framework:^4.1 for minor updates; test thoroughly before major versions.kid headers and KeySet).How can I help you explore Laravel packages today?