Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API Platform integration #1119

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection;

use ApiPlatform\Symfony\Bundle\ApiPlatformBundle;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -116,6 +117,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->arrayNode('api_platform')
->canBeEnabled()
->info('API Platform compatibility: add check_path in OpenAPI documentation.')
->children()
->scalarNode('check_path')
Expand Down
20 changes: 10 additions & 10 deletions DependencyInjection/LexikJWTAuthenticationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('lexik_jwt_authentication.encoder.signature_algorithm', $encoderConfig['signature_algorithm']);
$container->setParameter('lexik_jwt_authentication.encoder.crypto_engine', $encoderConfig['crypto_engine']);

$tokenExtractors = self::createTokenExtractors($container, $config['token_extractors']);
$tokenExtractors = $this->createTokenExtractors($container, $config['token_extractors']);
$container
->getDefinition('lexik_jwt_authentication.extractor.chain_extractor')
->replaceArgument(0, $tokenExtractors);
Expand Down Expand Up @@ -144,11 +144,11 @@ public function load(array $configs, ContainerBuilder $container): void
->replaceArgument(4, $encoderConfig['signature_algorithm']);
}

if (!class_exists(ApiPlatformBundle::class) && (isset($config['api_platform']['check_path']) || isset($config['api_platform']['username_path']) || isset($config['api_platform']['password_path']))) {
throw new LogicException('API Platform cannot be detected. Try running "composer require api-platform/core".');
}
if ($this->isConfigEnabled($container, $config['api_platform'])) {
if (!class_exists(ApiPlatformBundle::class)) {
throw new LogicException('API Platform cannot be detected. Try running "composer require api-platform/core".');
}

if (class_exists(ApiPlatformBundle::class)) {
$loader->load('api_platform.xml');

$container
Expand All @@ -159,11 +159,11 @@ public function load(array $configs, ContainerBuilder $container): void
}
}

private static function createTokenExtractors(ContainerBuilder $container, array $tokenExtractorsConfig)
private function createTokenExtractors(ContainerBuilder $container, array $tokenExtractorsConfig): array
{
$map = [];

if ($tokenExtractorsConfig['authorization_header']['enabled']) {
if ($this->isConfigEnabled($container, $tokenExtractorsConfig['authorization_header'])) {
$authorizationHeaderExtractorId = 'lexik_jwt_authentication.extractor.authorization_header_extractor';
$container
->getDefinition($authorizationHeaderExtractorId)
Expand All @@ -173,7 +173,7 @@ private static function createTokenExtractors(ContainerBuilder $container, array
$map[] = new Reference($authorizationHeaderExtractorId);
}

if ($tokenExtractorsConfig['query_parameter']['enabled']) {
if ($this->isConfigEnabled($container, $tokenExtractorsConfig['query_parameter'])) {
$queryParameterExtractorId = 'lexik_jwt_authentication.extractor.query_parameter_extractor';
$container
->getDefinition($queryParameterExtractorId)
Expand All @@ -182,7 +182,7 @@ private static function createTokenExtractors(ContainerBuilder $container, array
$map[] = new Reference($queryParameterExtractorId);
}

if ($tokenExtractorsConfig['cookie']['enabled']) {
if ($this->isConfigEnabled($container, $tokenExtractorsConfig['cookie'])) {
$cookieExtractorId = 'lexik_jwt_authentication.extractor.cookie_extractor';
$container
->getDefinition($cookieExtractorId)
Expand All @@ -191,7 +191,7 @@ private static function createTokenExtractors(ContainerBuilder $container, array
$map[] = new Reference($cookieExtractorId);
}

if ($tokenExtractorsConfig['split_cookie']['enabled']) {
if ($this->isConfigEnabled($container, $tokenExtractorsConfig['split_cookie'])) {
$cookieExtractorId = 'lexik_jwt_authentication.extractor.split_cookie_extractor';
$container
->getDefinition($cookieExtractorId)
Expand Down