The start of something beautiful
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* Exception that should be thrown from an authenticator during the authentication process
|
||||
* if a token is expired.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class ExpiredTokenException extends AuthenticationException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMessageKey(): string
|
||||
{
|
||||
return 'Expired JWT Token';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* Missing key in the token payload during authentication.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class InvalidPayloadException extends AuthenticationException
|
||||
{
|
||||
private string $invalidKey;
|
||||
|
||||
/**
|
||||
* @param string $invalidKey The key that cannot be found in the payload
|
||||
*/
|
||||
public function __construct(string $invalidKey)
|
||||
{
|
||||
$this->invalidKey = $invalidKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMessageKey(): string
|
||||
{
|
||||
return sprintf('Unable to find key "%s" in the token payload.', $this->invalidKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* Exception to be thrown in case of invalid token during an authentication process.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class InvalidTokenException extends AuthenticationException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMessageKey(): string
|
||||
{
|
||||
return 'Invalid JWT Token';
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
/**
|
||||
* JWTDecodeFailureException is thrown if an error occurs in the token decoding process.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTDecodeFailureException extends JWTFailureException
|
||||
{
|
||||
public const INVALID_TOKEN = 'invalid_token';
|
||||
|
||||
public const UNVERIFIED_TOKEN = 'unverified_token';
|
||||
|
||||
public const EXPIRED_TOKEN = 'expired_token';
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
/**
|
||||
* JWTEncodeFailureException is thrown if an error occurs in the token encoding process.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTEncodeFailureException extends JWTFailureException
|
||||
{
|
||||
public const INVALID_CONFIG = 'invalid_config';
|
||||
|
||||
public const UNSIGNED_TOKEN = 'unsigned_token';
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
/**
|
||||
* Base class for exceptions thrown during JWT creation/loading.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class JWTFailureException extends \Exception
|
||||
{
|
||||
private string $reason;
|
||||
private ?array $payload;
|
||||
|
||||
public function __construct(string $reason, string $message, \Throwable $previous = null, array $payload = null)
|
||||
{
|
||||
$this->reason = $reason;
|
||||
$this->payload = $payload;
|
||||
|
||||
parent::__construct($message, 0, $previous);
|
||||
}
|
||||
|
||||
public function getReason(): string
|
||||
{
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
public function getPayload(): ?array
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class MissingClaimException extends JWTFailureException
|
||||
{
|
||||
public function __construct(
|
||||
string $claim,
|
||||
Throwable $previous = null
|
||||
) {
|
||||
parent::__construct('missing_claim', sprintf('Missing required "%s" claim on JWT payload.', $claim), $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* Exception to be thrown in case of invalid token during an authentication process.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class MissingTokenException extends AuthenticationException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMessageKey(): string
|
||||
{
|
||||
return 'JWT Token not found';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Lexik\Bundle\JWTAuthenticationBundle\Exception;
|
||||
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
|
||||
/**
|
||||
* User not found during authentication.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
class UserNotFoundException extends AuthenticationException
|
||||
{
|
||||
private string $userIdentityField;
|
||||
private string $identity;
|
||||
|
||||
public function __construct(string $userIdentityField, string $identity)
|
||||
{
|
||||
$this->userIdentityField = $userIdentityField;
|
||||
$this->identity = $identity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMessageKey(): string
|
||||
{
|
||||
return sprintf('Unable to load an user with property "%s" = "%s". If the user identity has changed, you must renew the token. Otherwise, verify that the "lexik_jwt_authentication.user_identity_field" config option is correctly set.', $this->userIdentityField, $this->identity);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user