mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Created system of authentication plugins
This commit is contained in:
@@ -5,12 +5,7 @@ namespace Shlinkio\Shlink\Rest\Exception;
|
||||
|
||||
class AuthenticationException extends RuntimeException
|
||||
{
|
||||
public static function fromCredentials($username, $password)
|
||||
{
|
||||
return new self(sprintf('Invalid credentials. Username -> "%s". Password -> "%s"', $username, $password));
|
||||
}
|
||||
|
||||
public static function expiredJWT(\Exception $prev = null)
|
||||
public static function expiredJWT(\Exception $prev = null): self
|
||||
{
|
||||
return new self('The token has expired.', -1, $prev);
|
||||
}
|
||||
|
||||
18
module/Rest/src/Exception/NoAuthenticationException.php
Normal file
18
module/Rest/src/Exception/NoAuthenticationException.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Exception;
|
||||
|
||||
use function implode;
|
||||
use function sprintf;
|
||||
|
||||
class NoAuthenticationException extends RuntimeException
|
||||
{
|
||||
public static function fromExpectedTypes(array $expectedTypes): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'None of the valid authentication mechanisms where provided. Expected one of ["%s"]',
|
||||
implode('", "', $expectedTypes)
|
||||
));
|
||||
}
|
||||
}
|
||||
52
module/Rest/src/Exception/VerifyAuthenticationException.php
Normal file
52
module/Rest/src/Exception/VerifyAuthenticationException.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Rest\Exception;
|
||||
|
||||
use Throwable;
|
||||
use function sprintf;
|
||||
|
||||
class VerifyAuthenticationException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $errorCode;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $publicMessage;
|
||||
|
||||
public function __construct(
|
||||
string $errorCode,
|
||||
string $publicMessage,
|
||||
string $message = '',
|
||||
int $code = 0,
|
||||
Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->errorCode = $errorCode;
|
||||
$this->publicMessage = $publicMessage;
|
||||
}
|
||||
|
||||
public static function withError(string $errorCode, string $publicMessage, Throwable $prev = null): self
|
||||
{
|
||||
return new self(
|
||||
$errorCode,
|
||||
$publicMessage,
|
||||
sprintf('Authentication verification failed with the public message "%s"', $publicMessage),
|
||||
0,
|
||||
$prev
|
||||
);
|
||||
}
|
||||
|
||||
public function getErrorCode(): string
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
public function getPublicMessage(): string
|
||||
{
|
||||
return $this->publicMessage;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user