src/EventSubscriber/JwtAuthenticationSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Events;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  7. class JwtAuthenticationSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var TokenStorageInterface
  11.      */
  12.     private $tokenStorage;
  13.     /**
  14.      * JwtAuthenticationSubscriber constructor.
  15.      *
  16.      * @param TokenStorageInterface $tokenStorage
  17.      */
  18.     public function __construct(TokenStorageInterface $tokenStorage)
  19.     {
  20.         $this->tokenStorage $tokenStorage;
  21.     }
  22.     /**
  23.      * @return array
  24.      */
  25.     public static function getSubscribedEvents()
  26.     {
  27.         return [
  28.             Events::JWT_AUTHENTICATED => [
  29.                 ['storeJwtToken'1000],
  30.             ],
  31.         ];
  32.     }
  33.     /**
  34.      * @param JWTAuthenticatedEvent $event
  35.      */
  36.     public function storeJwtToken(JWTAuthenticatedEvent $event)
  37.     {
  38.         $token $event->getToken();
  39.         $this->tokenStorage->setToken($token);
  40.     }
  41. }