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,57 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor;
use Symfony\Component\HttpFoundation\Request;
/**
* AuthorizationHeaderTokenExtractor.
*
* @author Nicolas Cabot <n.cabot@lexik.fr>
*/
class AuthorizationHeaderTokenExtractor implements TokenExtractorInterface
{
/**
* @var string
*/
protected $prefix;
/**
* @var string
*/
protected $name;
/**
* @param string|null $prefix
* @param string $name
*/
public function __construct($prefix, $name)
{
$this->prefix = $prefix;
$this->name = $name;
}
/**
* {@inheritdoc}
*/
public function extract(Request $request)
{
if (!$request->headers->has($this->name)) {
return false;
}
$authorizationHeader = $request->headers->get($this->name);
if (empty($this->prefix)) {
return $authorizationHeader;
}
$headerParts = explode(' ', (string) $authorizationHeader);
if (!(2 === count($headerParts) && 0 === strcasecmp($headerParts[0], $this->prefix))) {
return false;
}
return $headerParts[1];
}
}
@@ -0,0 +1,96 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor;
use Symfony\Component\HttpFoundation\Request;
/**
* ChainTokenExtractor is the class responsible of extracting a JWT token
* from a {@link Request} object using all mapped token extractors.
*
* Note: The extractor map is reinitialized to the configured extractors for
* each different instance.
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
class ChainTokenExtractor implements \IteratorAggregate, TokenExtractorInterface
{
/**
* @var array
*/
private $map;
public function __construct(array $map)
{
$this->map = $map;
}
/**
* Adds a new token extractor to the map.
*/
public function addExtractor(TokenExtractorInterface $extractor)
{
$this->map[] = $extractor;
}
/**
* Removes a token extractor from the map.
*
* @param \Closure $filter A function taking an extractor as argument, used to find the extractor to remove.
*
* @return bool True in case of success, false otherwise
*/
public function removeExtractor(\Closure $filter)
{
$filtered = array_filter($this->map, $filter);
if (!$extractorToUnmap = current($filtered)) {
return false;
}
$key = array_search($extractorToUnmap, $this->map);
unset($this->map[$key]);
return true;
}
/**
* Clears the token extractor map.
*/
public function clearMap()
{
$this->map = [];
}
/**
* Iterates over the token extractors map calling {@see extract()}
* until a token is found.
*
* {@inheritdoc}
*/
public function extract(Request $request)
{
foreach ($this->getIterator() as $extractor) {
if ($token = $extractor->extract($request)) {
return $token;
}
}
return false;
}
/**
* Iterates over the mapped token extractors while generating them.
*
* @return \Traversable|TokenExtractorInterface[]
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
foreach ($this->map as $extractor) {
if ($extractor instanceof TokenExtractorInterface) {
yield $extractor;
}
}
}
}
@@ -0,0 +1,34 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor;
use Symfony\Component\HttpFoundation\Request;
/**
* CookieTokenExtractor.
*
* @author Nicolas Cabot <n.cabot@lexik.fr>
*/
class CookieTokenExtractor implements TokenExtractorInterface
{
/**
* @var string
*/
protected $name;
/**
* @param string $name
*/
public function __construct($name)
{
$this->name = $name;
}
/**
* {@inheritdoc}
*/
public function extract(Request $request)
{
return $request->cookies->get($this->name, false);
}
}
@@ -0,0 +1,34 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor;
use Symfony\Component\HttpFoundation\Request;
/**
* QueryParameterTokenExtractor.
*
* @author Nicolas Cabot <n.cabot@lexik.fr>
*/
class QueryParameterTokenExtractor implements TokenExtractorInterface
{
/**
* @var string
*/
protected $parameterName;
/**
* @param string $parameterName
*/
public function __construct($parameterName)
{
$this->parameterName = $parameterName;
}
/**
* {@inheritdoc}
*/
public function extract(Request $request)
{
return $request->query->get($this->parameterName, false);
}
}
@@ -0,0 +1,44 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor;
use Symfony\Component\HttpFoundation\Request;
/**
* SplitCookieExtractor.
*
* @author Adam Lukacovic <adam@adamlukacovic.sk>
*/
class SplitCookieExtractor implements TokenExtractorInterface
{
/**
* @var array
*/
private $cookies;
/**
* @param array $cookies
*/
public function __construct($cookies)
{
$this->cookies = $cookies;
}
/**
* {@inheritDoc}
*/
public function extract(Request $request)
{
$jwtCookies = [];
foreach ($this->cookies as $cookie) {
$jwtCookies[] = $request->cookies->get($cookie, false);
}
if (count($this->cookies) !== count(array_filter($jwtCookies))) {
return false;
}
return implode('.', $jwtCookies);
}
}
@@ -0,0 +1,18 @@
<?php
namespace Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor;
use Symfony\Component\HttpFoundation\Request;
/**
* TokenExtractorInterface.
*
* @author Nicolas Cabot <n.cabot@lexik.fr>
*/
interface TokenExtractorInterface
{
/**
* @return string|false
*/
public function extract(Request $request);
}