src/EventListener/JWTInvalidListener.php line 34

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: rostandnj
  5.  * Date: 19/3/19
  6.  * Time: 11:35 AM
  7.  */
  8. namespace App\EventListener;
  9. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTNotFoundEvent;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent;
  12. class JWTInvalidListener
  13. {
  14.     /**
  15.      * @param JWTNotFoundEvent $event
  16.      */
  17.     public function onJWTNotFound(JWTNotFoundEvent $event)
  18.     {
  19.         $data = [
  20.            'message'=>'Missing token',"code"=>'token_not_found','status'  => '403 Forbidden'
  21.         ];
  22.         $response = new JsonResponse($data403);
  23.         $event->setResponse($response);
  24.     }
  25.     /**
  26.      * @param JWTInvalidEvent $event
  27.      */
  28.     public function onJWTInvalid(JWTInvalidEvent $event)
  29.     {
  30.         $data = [
  31.             "message"=>"Invalid JWT Token","code"=>"invalid_jwt_token",'status'  => '403 Forbidden'
  32.         ];
  33.         $response = new JsonResponse($data403);
  34.         $event->setResponse($response);
  35.     }
  36. }