diff --git a/Security/Authentication/Provider/JWTProvider.php b/Security/Authentication/Provider/JWTProvider.php index 97693769..5c52a8c0 100644 --- a/Security/Authentication/Provider/JWTProvider.php +++ b/Security/Authentication/Provider/JWTProvider.php @@ -9,6 +9,7 @@ use Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator; use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTManagerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; @@ -90,7 +91,11 @@ public function authenticate(TokenInterface $token) $authToken->setRawToken($token->getCredentials()); $event = new JWTAuthenticatedEvent($payload, $authToken); - $this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, $event); + if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { + $this->dispatcher->dispatch($event, Events::JWT_AUTHENTICATED); + } else { + $this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, $event); + } return $authToken; } diff --git a/Security/Firewall/JWTListener.php b/Security/Firewall/JWTListener.php index d3445189..92c5a949 100644 --- a/Security/Firewall/JWTListener.php +++ b/Security/Firewall/JWTListener.php @@ -10,6 +10,7 @@ use Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator; use Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor\TokenExtractorInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; @@ -80,7 +81,12 @@ public function handle(GetResponseEvent $event) if (null === $requestToken) { $jwtNotFoundEvent = new JWTNotFoundEvent(); - $this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $jwtNotFoundEvent); + if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { + $this->dispatcher->dispatch($jwtNotFoundEvent, Events::JWT_NOT_FOUND); + } else { + $this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $jwtNotFoundEvent); + } + if ($response = $jwtNotFoundEvent->getResponse()) { $event->setResponse($response); @@ -105,7 +111,12 @@ public function handle(GetResponseEvent $event) $response = new JWTAuthenticationFailureResponse($failed->getMessage()); $jwtInvalidEvent = new JWTInvalidEvent($failed, $response); - $this->dispatcher->dispatch(Events::JWT_INVALID, $jwtInvalidEvent); + if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { + $this->dispatcher->dispatch($jwtInvalidEvent, Events::JWT_INVALID); + } else { + $this->dispatcher->dispatch(Events::JWT_INVALID, $jwtInvalidEvent); + } + $event->setResponse($jwtInvalidEvent->getResponse()); }