-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a request extractor API to replace the static method for extra…
…cting the refresh token from the request
- Loading branch information
Showing
18 changed files
with
460 additions
and
29 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
DependencyInjection/Compiler/AddExtractorsToChainCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class AddExtractorsToChainCompilerPass implements CompilerPassInterface | ||
{ | ||
use PriorityTaggedServiceTrait; | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('gesdinet.jwtrefreshtoken.request.extractor.chain')) { | ||
return; | ||
} | ||
|
||
$definition = $container->getDefinition('gesdinet.jwtrefreshtoken.request.extractor.chain'); | ||
|
||
foreach ($this->findAndSortTaggedServices('gesdinet_jwt_refresh_token.request_extractor', $container) as $extractorService) { | ||
$definition->addMethodCall('addExtractor', [$extractorService]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the GesdinetJWTRefreshTokenBundle package. | ||
* | ||
* (c) Gesdinet <http://www.gesdinet.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gesdinet\JWTRefreshTokenBundle\Request\Extractor; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class ChainExtractor implements ExtractorInterface | ||
{ | ||
/** | ||
* @var ExtractorInterface[] | ||
*/ | ||
private $extractors = []; | ||
|
||
public function addExtractor(ExtractorInterface $extractor): void | ||
{ | ||
$this->extractors[] = $extractor; | ||
} | ||
|
||
public function getRefreshToken(Request $request, string $parameter): ?string | ||
{ | ||
foreach ($this->extractors as $extractor) { | ||
if (null !== $token = $extractor->getRefreshToken($request, $parameter)) { | ||
return $token; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the GesdinetJWTRefreshTokenBundle package. | ||
* | ||
* (c) Gesdinet <http://www.gesdinet.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gesdinet\JWTRefreshTokenBundle\Request\Extractor; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
interface ExtractorInterface | ||
{ | ||
public function getRefreshToken(Request $request, string $parameter): ?string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the GesdinetJWTRefreshTokenBundle package. | ||
* | ||
* (c) Gesdinet <http://www.gesdinet.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gesdinet\JWTRefreshTokenBundle\Request\Extractor; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class RequestBodyExtractor implements ExtractorInterface | ||
{ | ||
public function getRefreshToken(Request $request, string $parameter): ?string | ||
{ | ||
if (false === strpos($request->getContentType(), 'json')) { | ||
return null; | ||
} | ||
|
||
$content = $request->getContent(); | ||
$params = !empty($content) ? json_decode($content, true) : []; | ||
|
||
return isset($params[$parameter]) ? trim($params[$parameter]) : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the GesdinetJWTRefreshTokenBundle package. | ||
* | ||
* (c) Gesdinet <http://www.gesdinet.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gesdinet\JWTRefreshTokenBundle\Request\Extractor; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class RequestParameterExtractor implements ExtractorInterface | ||
{ | ||
public function getRefreshToken(Request $request, string $parameter): ?string | ||
{ | ||
return $request->get($parameter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.