welcome back to dyb-tech

This commit is contained in:
Daniel Guzman
2024-05-18 02:28:01 +02:00
parent 9513cdba09
commit 9f30bc98c7
6149 changed files with 668407 additions and 0 deletions
@@ -0,0 +1,50 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* JWTAuthenticationFailureResponse.
*
* Response sent on failed JWT authentication (can be replaced by a custom Response).
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
final class JWTAuthenticationFailureResponse extends JWTCompatAuthenticationFailureResponse
{
private $message;
public function __construct(string $message = 'Bad credentials', int $statusCode = JsonResponse::HTTP_UNAUTHORIZED)
{
$this->message = $message;
parent::__construct(null, $statusCode, ['WWW-Authenticate' => 'Bearer']);
}
/**
* Sets the failure message.
*
* @param string $message
*
* @return JWTAuthenticationFailureResponse
*/
public function setMessage($message)
{
$this->message = $message;
$this->setData();
return $this;
}
/**
* Gets the failure message.
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
}
@@ -0,0 +1,32 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Response sent on successful JWT authentication.
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
final class JWTAuthenticationSuccessResponse extends JsonResponse
{
/**
* @param string $token Json Web Token
* @param array $data Extra data passed to the response
*/
public function __construct($token, array $data = [], array $jwtCookies = [])
{
if (!$jwtCookies) {
parent::__construct(['token' => $token] + $data);
return;
}
parent::__construct($data);
foreach ($jwtCookies as $cookie) {
$this->headers->setCookie($cookie);
}
}
}
@@ -0,0 +1,58 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* The "AND" in the if statement is a temporary fix for the following issue:
* https://github.com/lexik/LexikJWTAuthenticationBundle/issues/944
* https://github.com/vimeo/psalm/issues/7923
*/
if (80000 <= \PHP_VERSION_ID and (new \ReflectionMethod(JsonResponse::class, 'setData'))->hasReturnType()) {
eval('
namespace Lexik\Bundle\JWTAuthenticationBundle\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Compatibility layer for Symfony 6.0 and later.
*
* @internal
*/
abstract class JWTCompatAuthenticationFailureResponse extends JsonResponse
{
/**
* Sets the response data with the statusCode & message included.
*
* {@inheritdoc}
*
* @return static
*/
public function setData($data = []): static
{
return parent::setData((array)$data + ["code" => $this->statusCode, "message" => $this->getMessage()]);
}
}
');
} else {
/**
* Compatibility layer for Symfony 5.4 and earlier.
*
* @internal
*/
abstract class JWTCompatAuthenticationFailureResponse extends JsonResponse
{
/**
* Sets the response data with the statusCode & message included.
*
* {@inheritdoc}
*
* @return static
*/
public function setData($data = [])
{
return parent::setData((array)$data + ['code' => $this->statusCode, 'message' => $this->getMessage()]);
}
}
}