welcome back to dyb-tech
This commit is contained in:
Vendored
+57
@@ -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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user