The start of something beautiful
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* AuthenticationFailureEvent.
|
||||
*
|
||||
* @author Emmanuel Vella <vella.emmanuel@gmail.com>
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class AuthenticationFailureEvent extends Event
|
||||
{
|
||||
protected AuthenticationException $exception;
|
||||
protected ?Response $response;
|
||||
protected ?Request $request;
|
||||
|
||||
public function __construct(?AuthenticationException $exception, ?Response $response, ?Request $request = null)
|
||||
{
|
||||
$this->exception = $exception;
|
||||
$this->response = $response;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function getException(): AuthenticationException
|
||||
{
|
||||
return $this->exception;
|
||||
}
|
||||
|
||||
public function getResponse(): ?Response
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function setResponse(Response $response): void
|
||||
{
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
public function getRequest(): ?Request
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
public function setRequest(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* AuthenticationSuccessEvent.
|
||||
*
|
||||
* @author Dev Lexik <dev@lexik.fr>
|
||||
*/
|
||||
class AuthenticationSuccessEvent extends Event
|
||||
{
|
||||
protected array $data;
|
||||
protected UserInterface $user;
|
||||
protected Response $response;
|
||||
|
||||
public function __construct(array $data, UserInterface $user, Response $response)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->user = $user;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setData(array $data): void
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getUser(): UserInterface
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getResponse(): Response
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
/**
|
||||
* BeforeJWEComputationEvent event is dispatched just before the computation of the encrypted token.
|
||||
* This can be used to add or modify the JWE header parameters.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class BeforeJWEComputationEvent
|
||||
{
|
||||
private $header;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $header
|
||||
*/
|
||||
public function __construct(array $header)
|
||||
{
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
public function setHeader(string $key, mixed $value): self
|
||||
{
|
||||
$this->header[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeHeader(string $key): self
|
||||
{
|
||||
unset($this->header[$key]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getHeader(): array
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* JWTAuthenticatedEvent.
|
||||
*/
|
||||
class JWTAuthenticatedEvent extends Event
|
||||
{
|
||||
protected array $payload;
|
||||
protected TokenInterface $token;
|
||||
|
||||
public function __construct(array $payload, TokenInterface $token)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function getPayload(): array
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
public function setPayload(array $payload)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
public function getToken(): TokenInterface
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* JWTCreatedEvent.
|
||||
*/
|
||||
class JWTCreatedEvent extends Event
|
||||
{
|
||||
protected array $header;
|
||||
protected array $data;
|
||||
protected UserInterface $user;
|
||||
|
||||
public function __construct(array $data, UserInterface $user, array $header = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->user = $user;
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
public function getHeader(): array
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
public function setHeader(array $header)
|
||||
{
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setData(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getUser(): UserInterface
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* JWTDecodedEvent.
|
||||
*
|
||||
* @author Nicolas Cabot <n.cabot@lexik.fr>
|
||||
*/
|
||||
class JWTDecodedEvent extends Event
|
||||
{
|
||||
protected array $payload;
|
||||
protected bool $isValid;
|
||||
|
||||
public function __construct(array $payload)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
$this->isValid = true;
|
||||
}
|
||||
|
||||
public function getPayload(): array
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
public function setPayload(array $payload)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark payload as invalid.
|
||||
*/
|
||||
public function markAsInvalid(): void
|
||||
{
|
||||
$this->isValid = false;
|
||||
$this->stopPropagation();
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->isValid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
class JWTEncodedEvent extends Event
|
||||
{
|
||||
private string $jwtString;
|
||||
|
||||
public function __construct(string $jwtString)
|
||||
{
|
||||
$this->jwtString = $jwtString;
|
||||
}
|
||||
|
||||
public function getJWTString(): string
|
||||
{
|
||||
return $this->jwtString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
/**
|
||||
* JWTExpiredEvent.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTExpiredEvent extends AuthenticationFailureEvent implements JWTFailureEventInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* Interface for event classes that are dispatched when a JWT cannot be authenticated.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
interface JWTFailureEventInterface
|
||||
{
|
||||
/**
|
||||
* Gets the response that will be returned after dispatching a
|
||||
* {@link JWTFailureEventInterface} implementation.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getResponse();
|
||||
|
||||
/**
|
||||
* Gets the tied AuthenticationException object.
|
||||
*
|
||||
* @return AuthenticationException
|
||||
*/
|
||||
public function getException();
|
||||
|
||||
/**
|
||||
* Calling this allows to return a custom Response immediately after
|
||||
* the corresponding implementation of this event is dispatched.
|
||||
*/
|
||||
public function setResponse(Response $response);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
/**
|
||||
* JWTInvalidEvent.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTInvalidEvent extends AuthenticationFailureEvent implements JWTFailureEventInterface
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* JWTNotFoundEvent event is dispatched when a JWT cannot be found in a request
|
||||
* covered by a firewall secured via lexik_jwt.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTNotFoundEvent extends AuthenticationFailureEvent implements JWTFailureEventInterface
|
||||
{
|
||||
public function __construct(AuthenticationException $exception = null, Response $response = null, Request $request = null)
|
||||
{
|
||||
parent::__construct($exception, $response, $request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user