src/EventListener/CustomJWTEventListener.php line 20
<?php
namespace App\EventListener;
use App\Service\BlacklistService;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
class CustomJWTEventListener
{
private $blacklistService;
public function __construct(BlacklistService $blacklistService)
{
$this->blacklistService = $blacklistService;
}
public function onKernelRequest(RequestEvent $event)
{
try {
$request = $event->getRequest();
$credentials = $request->headers->get('Authorization');
$token = str_replace('Bearer ', '', $credentials);
if ($this->blacklistService->isBlacklisted($token)) {
throw new NotFoundHttpException('This token has been blacklisted.');
}
} catch (NotFoundHttpException $exception) {
throw new NotFoundHttpException($exception->getMessage());
}
}
}