Explorar el Código

iri wip

master
Daniel hace 2 años
padre
commit
b1bcca3a2f
Se han modificado 2 ficheros con 11 adiciones y 3 borrados
  1. +2
    -1
      config/services.yaml
  2. +9
    -2
      src/EventListener/AuthenticationSuccessListener.php

+ 2
- 1
config/services.yaml Ver fichero

@@ -26,4 +26,5 @@ services:
acme_api.event.authentication_success_listener: acme_api.event.authentication_success_listener:
class: App\EventListener\AuthenticationSuccessListener class: App\EventListener\AuthenticationSuccessListener
tags: tags:
- { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse }
- { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse }
arguments: ['@api_platform.iri_converter']

+ 9
- 2
src/EventListener/AuthenticationSuccessListener.php Ver fichero

@@ -8,16 +8,22 @@
namespace App\EventListener; namespace App\EventListener;




use ApiPlatform\Api\IriConverterInterface;
use App\Entity\User; use App\Entity\User;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent; use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Symfony\Component\Security\Core\User\UserInterface;


class AuthenticationSuccessListener class AuthenticationSuccessListener
{ {
public function __construct(private IriConverterInterface $iriConverter)
{
}

/** /**
* @param AuthenticationSuccessEvent $event * @param AuthenticationSuccessEvent $event
*/ */
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event): void
public function onAuthenticationSuccessResponse(
AuthenticationSuccessEvent $event
): void
{ {
$data = $event->getData(); $data = $event->getData();
$user = $event->getUser(); $user = $event->getUser();
@@ -26,6 +32,7 @@ class AuthenticationSuccessListener
return; return;
} }


$data['id'] = $this->iriConverter->getIriFromResource($user);
$data['email'] = $user->getEmail(); $data['email'] = $user->getEmail();
$data['firstName'] = $user->getFirstName(); $data['firstName'] = $user->getFirstName();
$data['lastName'] = $user->getLastName(); $data['lastName'] = $user->getLastName();


Cargando…
Cancelar
Guardar