From a677b383c47cbf68569942647d7576c82a47b265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Perron?= Date: Wed, 29 Nov 2023 09:07:31 -0500 Subject: [PATCH] fix: throw LogicException when partitioned option is used in Symfony <6.4 --- DependencyInjection/LexikJWTAuthenticationExtension.php | 5 +++++ Security/Http/Cookie/JWTCookieProvider.php | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/DependencyInjection/LexikJWTAuthenticationExtension.php b/DependencyInjection/LexikJWTAuthenticationExtension.php index 7000da41..a91b5712 100644 --- a/DependencyInjection/LexikJWTAuthenticationExtension.php +++ b/DependencyInjection/LexikJWTAuthenticationExtension.php @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\HttpKernel\Kernel; /** * This is the class that loads and manages your bundle configuration. @@ -115,6 +116,10 @@ public function load(array $configs, ContainerBuilder $container): void $cookieProviders = []; foreach ($config['set_cookies'] as $name => $attributes) { + if ($attributes['partitioned'] && Kernel::VERSION < '6.4') { + throw new \LogicException(sprintf('The `partitioned` option for cookies is only available for Symfony 6.4 and above. You are currently on version %s', Kernel::VERSION)); + } + $container ->setDefinition($id = "lexik_jwt_authentication.cookie_provider.$name", new ChildDefinition('lexik_jwt_authentication.cookie_provider')) ->replaceArgument(0, $name) diff --git a/Security/Http/Cookie/JWTCookieProvider.php b/Security/Http/Cookie/JWTCookieProvider.php index 87358357..460af6e7 100644 --- a/Security/Http/Cookie/JWTCookieProvider.php +++ b/Security/Http/Cookie/JWTCookieProvider.php @@ -4,6 +4,7 @@ use Lexik\Bundle\JWTAuthenticationBundle\Helper\JWTSplitter; use Symfony\Component\HttpFoundation\Cookie; +use Symfony\Component\HttpKernel\Kernel; /** * Creates secure JWT cookies. @@ -31,6 +32,10 @@ public function __construct(?string $defaultName = null, ?int $defaultLifetime = $this->defaultHttpOnly = $defaultHttpOnly; $this->defaultSplit = $defaultSplit; $this->defaultPartitioned = $defaultPartitioned; + + if ($defaultPartitioned && Kernel::VERSION < '6.4') { + throw new \LogicException(sprintf('The `partitioned` option for cookies is only available for Symfony 6.4 and above. You are currently on version %s', Kernel::VERSION)); + } } /** @@ -49,6 +54,10 @@ public function createCookie(string $jwt, ?string $name = null, $expiresAt = nul throw new \LogicException(sprintf('The cookie expiration time must be provided, either pass it as 3rd argument of %s or set a default lifetime via the constructor.', __METHOD__)); } + if ($partitioned && Kernel::VERSION < '6.4') { + throw new \LogicException(sprintf('The `partitioned` option for cookies is only available for Symfony 6.4 and above. You are currently on version %s', Kernel::VERSION)); + } + $jwtParts = new JWTSplitter($jwt); $jwt = $jwtParts->getParts($split ?: $this->defaultSplit);