lexik/jwt-authentication-bundle
JWT authentication bundle for Symfony APIs. Issues and validates JSON Web Tokens, supports PHP 8.2+ and Symfony 6.4–8, and offers extensive docs for setup, configuration, customization, testing, CORS, and programmatic token creation.
JWTEncodedEvent, AuthenticationSuccessEvent) for extensibility without core modifications.OpenSSLKeyLoader for dynamic key generation or integrate with a secrets manager (e.g., HashiCorp Vault).HttpOnly, Secure cookies) early in design.ExtensionInterface).aud, iss).tenant_id claim)? This affects token validation logic.authentication_listener configuration.api_login firewall).localStorage (with caution) or HttpOnly cookies.Keychain (iOS) or SharedPreferences (Android)./auth/login) to test token generation/validation.JWTTokenExtractor to validate existing auth flows.Authorization: Bearer <token> headers.deprecated attribute or custom middleware to warn clients before removing old endpoints.JWTEncoder/JWTDecoder to manually create/validate tokens.cors_origin in the bundle to allow frontend domains. Use WWW-Authenticate headers for failed requests.composer require lexik/jwt-authentication-bundle.config/packages/security.yaml and config/packages/lexik_jwt_authentication.yaml.mkdir -p config/jwt && openssl genpkey -out config/jwt/private.pem -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096 and generate public key.JWTEncodedEvent to customize token payloads (e.g., add user_id).JWTTokenExtractor.POST /auth/login).GET /api/resource with Authorization header).JWTTestTrait for unit tests.JWT_SECRET_KEY and JWT_PUBLIC_KEY environment variables.JWT_TTL (e.g., 3600 for 1 hour) and JWT_REFRESH_TTL (e.g., 86400 for 1 day).OpenSSLKeyLoader for dynamic key generation or integrate with Vault.nbf (not before) claims to phase out old keys.# config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
secret_key: '%env(JWT_SECRET_KEY)%'
public_key: '%env(JWT_PUBLIC_KEY)%'
pass_phrase: '%env(JWT_PASSPHRASE)%'
user_identity_field: username
token_ttl: '%env(int:JWT_TTL, 3600)%'
Cache-Control headers reflect TTL.nbf/exp claims).Access-Control-Allow-Origin headers can block frontend requests.JWTAuthenticationListener logs to trace authentication failures.AuthenticationFailureEvent payloads.POST /auth/refresh with refresh token).How can I help you explore Laravel packages today?