src/EventListener/JWTExpiredListener.php line 14

Open in your IDE?
  1. <?php 
  2. namespace App\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTExpiredEvent;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. class JWTExpiredListener {
  7.   /**
  8.    * @param JWTExpiredEvent $event
  9.    */
  10.   public function onJWTExpiredResponse(JWTExpiredEvent $event)
  11.   {
  12.     $data = array(
  13.       'error' => true,
  14.       'status' => 'token_expired',
  15.       'message' => array(
  16.         'fr' => 'Token expiré',
  17.         'en' => 'Expired token'
  18.       )
  19.     );
  20.     $response = new JWTAuthenticationFailureResponse('token_expired'JsonResponse::HTTP_UNAUTHORIZED);
  21.     $response->setData($data);
  22.     $event->setResponse($response);
  23.   }
  24. }