for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Guarded Authentication package.
*
* (c) Jafar Jabr <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jafar\Bundle\GuardedAuthenticationBundle\Api\JWSExtractor;
use Symfony\Component\HttpFoundation\Request;
/**
* Class TokenExtractor.
* @author Jafar Jabr <[email protected]>
final class TokenExtractor implements TokenExtractorInterface
{
* @var string
private $prefix;
private $name;
* @param string $prefix
* @param string $name
public function __construct(string $prefix, string $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(' ', $authorizationHeader);
if (!(2 === count($headerParts) && $headerParts[0] === $this->prefix)) {
return $headerParts[1];