lib/boab/cms-bundle/src/Api/EventListener/JWTDecodedListener.php line 21

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\Api\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent;
  4. class JWTDecodedListener
  5. {
  6.     private $requestStack;
  7.     public function __construct($request)
  8.     {
  9.         $this->requestStack $request;
  10.     }
  11.     /**
  12.      * @param JWTDecodedEvent $event
  13.      *
  14.      * @return void
  15.      */
  16.     public function onJWTDecoded(JWTDecodedEvent $event)
  17.     {
  18.         $request $this->requestStack->getCurrentRequest();
  19.         
  20.         $payload $event->getPayload();
  21.         $request->attributes->set('userId',$payload['userId']);
  22.         $request->attributes->set('username',$payload['username']);
  23.         if (!isset($payload['ip']) || $payload['ip'] !== $request->getClientIp()) {
  24.             //die($payload['username']);
  25.             //$event->markAsInvalid();
  26.         }
  27.     }    
  28. }