- Can I use abotteram/jwt-bundle directly in a Laravel project without Symfony?
- No, this bundle is Symfony-first and requires adaptation. You’ll need to manually bind its JWT encoder/decoder services to Laravel’s container and replace Symfony-specific components (like guards) with Laravel middleware or traits. Start with a proof-of-concept to test core functionality before full integration.
- What Laravel versions does this bundle support?
- The bundle itself targets Symfony, but its underlying JWT logic (via firebase/php-jwt) is framework-agnostic. Laravel compatibility depends on your custom integration layer. Test with Laravel 8.x+ for modern DI compatibility, but Symfony-specific features may not align.
- How do I generate and validate JWT tokens in Laravel using this bundle?
- Bind the bundle’s `JWTEncoderInterface` and `JWTDecoderInterface` to Laravel’s service container, then create a facade or helper class (e.g., `JwtHelper::generateToken($payload)`). For validation, use middleware to decode tokens and check claims against your Laravel user model.
- Does this bundle support Laravel’s built-in authentication system?
- Not natively. You’ll need to replace Symfony’s `AuthenticationGuard` with Laravel middleware that uses the bundle’s decoder to validate tokens. Pair it with Laravel’s `AuthenticatesUsers` trait or a custom guard for session-based auth workflows.
- Are there performance concerns using this Symfony bundle in Laravel?
- Potential overhead exists due to Symfony’s event system and reflection-based DI. Mitigate this by directly injecting the bundle’s core services (e.g., `JWTEncoder`) and avoiding unnecessary Symfony abstractions. Benchmark token generation/validation in your Laravel environment.
- How do I handle token expiration and refresh logic in Laravel?
- Use the bundle’s `JWTDecoder` to check expiration claims (`exp`). For refresh tokens, implement a Laravel event listener (e.g., `JWTExpired`) or middleware to trigger re-authentication. Store refresh tokens in Laravel’s database or cache with a TTL.
- What alternatives should I consider for Laravel JWT auth?
- For native Laravel support, evaluate `spatie/laravel-jwt` (simpler, Laravel-optimized) or `tymon/jwt-auth` (feature-rich, middleware-based). If you need Symfony interop, consider `lexik/jwt-authentication-bundle` (Symfony-only) or build a custom wrapper around `firebase/php-jwt`.
- How do I configure this bundle for Laravel’s service providers?
- Create a custom Laravel service provider to register the bundle’s services. Override Symfony’s `Extension` class to output Laravel-compatible config (e.g., `config/jwt.php`). Example: `JwtBundle::registerServices($this->app);` in your `AppServiceProvider` boot method.
- Will this bundle work with Laravel’s Sanctum or Passport for API auth?
- No, this bundle is JWT-focused and doesn’t integrate with Sanctum/Passport. Use it as a standalone token generator/validator alongside Sanctum/Passport for session/API hybrid auth. Avoid redundancy by picking one auth system per project.
- How do I test JWT token generation/validation in Laravel?
- Mock the bundle’s services in PHPUnit tests using Laravel’s `Mockery` or `createMock()`. Test edge cases like expired tokens, malformed payloads, and custom claims. Example: `$encoder = $this->mock(JWTEncoderInterface::class); $encoder->shouldReceive('encode')->andReturn('valid.token');`