memory

Play Memory
Log | Files | Refs

JWTCreatedListener.php (1114B)


      1 <?php
      2 namespace App\EventListener;
      3 
      4 
      5 use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
      6 use Symfony\Component\HttpFoundation\RequestStack;
      7 
      8 // Toegevoegd om de userid in de header van de JWT te krijgen.
      9 // https://github.com/lexik/LexikJWTAuthenticationBundle/blob/2.x/Resources/doc/2-data-customization.rst
     10 class JWTCreatedListener {
     11     private $requestStack;
     12 
     13     public function __construct(RequestStack $requestStack)
     14     {
     15         $this->requestStack = $requestStack;
     16     }
     17 
     18 
     19     public function onJWTCreated(JWTCreatedEvent $event)
     20     {
     21         $payload = $event->getData();
     22         $payload['sub'] = $event->getUser()->id;
     23         $payload['iss'] = 'memory backend';
     24 
     25         $event->setData($payload);
     26 
     27         // @Deprecated
     28         // foutje, deze data moet in de payload, niet in de header.
     29         // dit zit er nog in voor backward compatibility
     30         //https://www.rfc-editor.org/rfc/rfc7519#section-4.1
     31         $header = $event->getHeader();
     32         $header['sub'] =  $event->getUser()->id;
     33         $header['iss'] = 'memory backend';
     34 
     35         $event->setHeader($header);
     36     }
     37 }
     38 
     39 
     40