From b1bcca3a2f422834ea501b7bf0881f253c942246 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 18 Jan 2024 16:09:56 +0100 Subject: [PATCH] iri wip --- config/services.yaml | 3 ++- src/EventListener/AuthenticationSuccessListener.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 33b2e72..fdfd18b 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -26,4 +26,5 @@ services: acme_api.event.authentication_success_listener: class: App\EventListener\AuthenticationSuccessListener tags: - - { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse } \ No newline at end of file + - { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse } + arguments: ['@api_platform.iri_converter'] \ No newline at end of file diff --git a/src/EventListener/AuthenticationSuccessListener.php b/src/EventListener/AuthenticationSuccessListener.php index ae3c082..772297f 100644 --- a/src/EventListener/AuthenticationSuccessListener.php +++ b/src/EventListener/AuthenticationSuccessListener.php @@ -8,16 +8,22 @@ namespace App\EventListener; +use ApiPlatform\Api\IriConverterInterface; use App\Entity\User; use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent; -use Symfony\Component\Security\Core\User\UserInterface; class AuthenticationSuccessListener { + public function __construct(private IriConverterInterface $iriConverter) + { + } + /** * @param AuthenticationSuccessEvent $event */ - public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event): void + public function onAuthenticationSuccessResponse( + AuthenticationSuccessEvent $event + ): void { $data = $event->getData(); $user = $event->getUser(); @@ -26,6 +32,7 @@ class AuthenticationSuccessListener return; } + $data['id'] = $this->iriConverter->getIriFromResource($user); $data['email'] = $user->getEmail(); $data['firstName'] = $user->getFirstName(); $data['lastName'] = $user->getLastName();