k3progetti/jwt-bundle

Bundle Symfony per la gestione dei token JWT con supporto a refresh token e logout

Installs: 16

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

v1.1.20 2025-03-31 09:56 UTC

README

Bundle Symfony per la gestione avanzata dei token JWT, con supporto a:

  • Login e generazione token JWT
  • Refresh token
  • Logout e invalidazione dei token
  • Comandi da terminale per la pulizia dei token scaduti

βœ… Requisiti

  • PHP >= 8.2
  • Symfony 7.0

πŸš€ Installazione

composer require k3progetti/jwt-bundle

βš™οΈ Configurazione

πŸ“¦ Registrazione del bundle

Aggiungi il bundle al tuo config/bundles.php se non viene registrato automaticamente:

return [
    // ...
    K3Progetti\JwtBundle\JwtBundle::class => ['all' => true],
];

πŸ” Configurazione del firewall (config/packages/security.yaml)

firewalls:
    api:
        pattern: ^/api/
        stateless: true
        custom_authenticator: K3Progetti\JwtBundle\Security\JwtAuthenticator

🧱 Migrazioni

Il bundle include due entitΓ : JwtToken e JwtRefreshToken.
Dopo aver installato il bundle, genera e applica le migrazioni:

php bin/console make:migration
php bin/console doctrine:migrations:migrate

🧭 Struttura del Progetto

JwtBundle/
β”œβ”€β”€ JwtBundle.php
β”œβ”€β”€ bin/
β”‚   └── register-jwt-bundle.php
β”œβ”€β”€ resources/
β”‚   └── config/
β”‚       └── services.yaml
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Command/
β”‚   β”‚   β”œβ”€β”€ RemoveJwtRefreshTokenExpired.php
β”‚   β”‚   β”œβ”€β”€ RemoveJwtTokenExpired.php
β”‚   β”‚   └── RemoveJwtTokenUser.php
β”‚   β”œβ”€β”€ Controller/
β”‚   β”‚   └── AuthController.php
β”‚   β”œβ”€β”€ DependencyInjection/
β”‚   β”‚   β”œβ”€β”€ Configuration.php
β”‚   β”‚   └── JwtExtension.php
β”‚   β”œβ”€β”€ Entity/
β”‚   β”‚   β”œβ”€β”€ JwtToken.php
β”‚   β”‚   └── JwtRefreshToken.php
β”‚   β”œβ”€β”€ Event/
β”‚   β”‚   └── JwtUserLoggedOutEvent.php
β”‚   β”œβ”€β”€ Helper/
β”‚   β”‚   └── AuthHelper.php
β”‚   β”œβ”€β”€ Repository/
β”‚   β”‚   β”œβ”€β”€ JwtTokenRepository.php
β”‚   β”‚   └── JwtRefreshTokenRepository.php
β”‚   β”œβ”€β”€ Security/
β”‚   β”‚   β”œβ”€β”€ JwtAuthenticator.php
β”‚   β”‚   └── Handler/
β”‚   β”‚       β”œβ”€β”€ LoginHandler.php
β”‚   β”‚       β”œβ”€β”€ LogoutHandler.php
β”‚   β”‚       └── RefreshTokenHandler.php
β”‚   └── Service/
β”‚       β”œβ”€β”€ JwtService.php
β”‚       └── JwtRefreshService.php

πŸ”§ Comandi Console Disponibili

bin/console jwt:remove-jwt-refresh-token-expired
bin/console jwt:remove-jwt-token-expired
bin/console jwt:remove-jwt-token-user

🀝 Contributi

Sono aperto a qualsiasi confronto.