Skip to content

Commit ba86546

Browse files
committed
feature #1300 feat: Support Symfony 8.x & web-token suite 4.x (dt-thomas-durand)
This PR was merged into the 3.x branch. Discussion ---------- feat: Support Symfony 8.x & web-token suite 4.x - Rewrote the configuration in php instead of xml (XML is deleted in Symfony 8) - Fixed Coding Standard ; and UT - Added support for web-token suite 4.x ; required to use Symfony 8 Commits ------- 570a64d feat: Support Symfony 8.x
2 parents ff16ec6 + 570a64d commit ba86546

37 files changed

+498
-373
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jobs:
1717
symfony: 6.4.*
1818
can-fail: false
1919
# LTS with last stable PHP
20-
- php: 8.3
20+
- php: 8.4
2121
symfony: 6.4.*
2222
can-fail: false
23-
# Stable Symfony branches
24-
- php: 8.3
25-
symfony: 7.1.*
23+
# Stable Symfony branches
24+
- php: 8.4
25+
symfony: 7.4.*
2626
can-fail: false
2727
- php: 8.4
28-
symfony: 7.2.*
28+
symfony: 8.0.*
2929
can-fail: false
3030

3131
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"

.github/workflows/web-token-ci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ jobs:
1515
# Lowest deps
1616
- php: 8.2
1717
symfony: 6.4.*
18+
jwt-bundle: 3.3
1819
can-fail: false
1920
# LTS with last stable PHP
20-
- php: 8.3
21+
- php: 8.4
2122
symfony: 6.4.*
23+
jwt-bundle: 3.3
2224
can-fail: false
23-
# Stable Symfony branches
24-
- php: 8.3
25-
symfony: 7.1.*
25+
# Stable Symfony branches
26+
- php: 8.4
27+
symfony: 7.4.*
28+
jwt-bundle: 4.0
2629
can-fail: false
2730
- php: 8.4
28-
symfony: 7.2.*
31+
symfony: 8.0.*
32+
jwt-bundle: 4.1
2933
can-fail: false
3034

3135
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
@@ -51,7 +55,7 @@ jobs:
5155

5256
- name: "Require web-token/*"
5357
run: |
54-
composer require --dev --no-update web-token/jwt-bundle:"^3.3.3"
58+
composer require --dev --no-update web-token/jwt-bundle:"^${{ matrix.jwt-bundle }}"
5559
composer require --dev --no-update spomky-labs/aes-key-wrap:"^7.0"
5660
5761
- name: "Install dependencies"

Command/EnableEncryptionConfigCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Jose\Component\Core\AlgorithmManagerFactory;
99
use Jose\Component\Core\JWK;
1010
use Jose\Component\Core\JWKSet;
11+
use Jose\Component\Core\Util\Base64UrlSafe;
1112
use Jose\Component\Encryption\Algorithm\ContentEncryptionAlgorithm;
1213
use Jose\Component\Encryption\Algorithm\KeyEncryptionAlgorithm;
1314
use Jose\Component\Encryption\JWEBuilder;
@@ -16,7 +17,6 @@
1617
use Jose\Component\Signature\JWSBuilder;
1718
use Jose\Component\Signature\JWSLoader;
1819
use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\KeyLoaderInterface;
19-
use ParagonIE\ConstantTime\Base64UrlSafe;
2020
use Symfony\Bundle\FrameworkBundle\Command\AbstractConfigCommand;
2121
use Symfony\Component\Config\Definition\Processor;
2222
use Symfony\Component\Console\Attribute\AsCommand;

Command/MigrateConfigCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
use Jose\Component\Checker\ClaimCheckerManager;
77
use Jose\Component\Core\JWK;
88
use Jose\Component\Core\JWKSet;
9+
use Jose\Component\Core\Util\Base64UrlSafe;
910
use Jose\Component\KeyManagement\JWKFactory;
1011
use Jose\Component\Signature\JWSBuilder;
1112
use Jose\Component\Signature\JWSLoader;
1213
use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\KeyLoaderInterface;
13-
use ParagonIE\ConstantTime\Base64UrlSafe;
1414
use Symfony\Bundle\FrameworkBundle\Command\AbstractConfigCommand;
1515
use Symfony\Component\Config\Definition\Processor;
1616
use Symfony\Component\Console\Attribute\AsCommand;

DependencyInjection/LexikJWTAuthenticationExtension.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Exception\LogicException;
1616
use Symfony\Component\DependencyInjection\Extension\Extension;
17-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
17+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1818
use Symfony\Component\DependencyInjection\Reference;
1919
use Symfony\Component\HttpKernel\Kernel;
2020

@@ -33,14 +33,14 @@ public function load(array $configs, ContainerBuilder $container): void
3333
$configuration = new Configuration();
3434
$config = $this->processConfiguration($configuration, $configs);
3535

36-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
36+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
3737

38-
$loader->load('jwt_manager.xml');
39-
$loader->load('key_loader.xml');
40-
$loader->load('lcobucci.xml');
41-
$loader->load('response_interceptor.xml');
42-
$loader->load('token_authenticator.xml');
43-
$loader->load('token_extractor.xml');
38+
$loader->load('jwt_manager.php');
39+
$loader->load('key_loader.php');
40+
$loader->load('lcobucci.php');
41+
$loader->load('response_interceptor.php');
42+
$loader->load('token_authenticator.php');
43+
$loader->load('token_extractor.php');
4444

4545
if (empty($config['public_key']) && empty($config['secret_key'])) {
4646
$e = new InvalidConfigurationException('You must either configure a "public_key" or a "secret_key".');
@@ -89,7 +89,7 @@ public function load(array $configs, ContainerBuilder $container): void
8989
}
9090

9191
if ($config['set_cookies']) {
92-
$loader->load('cookie.xml');
92+
$loader->load('cookie.php');
9393

9494
$cookieProviders = [];
9595
foreach ($config['set_cookies'] as $name => $attributes) {
@@ -117,7 +117,7 @@ public function load(array $configs, ContainerBuilder $container): void
117117
}
118118

119119
if (class_exists(Application::class)) {
120-
$loader->load('console.xml');
120+
$loader->load('console.php');
121121

122122
$container
123123
->getDefinition('lexik_jwt_authentication.generate_keypair_command')
@@ -135,7 +135,7 @@ public function load(array $configs, ContainerBuilder $container): void
135135
throw new LogicException('API Platform cannot be detected. Try running "composer require api-platform/core".');
136136
}
137137

138-
$loader->load('api_platform.xml');
138+
$loader->load('api_platform.php');
139139

140140
$container
141141
->getDefinition('lexik_jwt_authentication.api_platform.openapi.factory')
@@ -147,7 +147,7 @@ public function load(array $configs, ContainerBuilder $container): void
147147
$this->processWithWebTokenConfig($config, $container, $loader);
148148

149149
if ($this->isConfigEnabled($container, $config['blocklist_token'])) {
150-
$loader->load('blocklist_token.xml');
150+
$loader->load('blocklist_token.php');
151151
$blockListTokenConfig = $config['blocklist_token'];
152152
$container->setAlias('lexik_jwt_authentication.blocklist_token.cache', $blockListTokenConfig['cache']);
153153
} else {
@@ -205,9 +205,9 @@ private function processWithWebTokenConfig(array $config, ContainerBuilder $cont
205205
if ($config['access_token_issuance']['enabled'] === false && $config['access_token_verification']['enabled'] === false) {
206206
return;
207207
}
208-
$loader->load('web_token.xml');
208+
$loader->load('web_token.php');
209209
if ($config['access_token_issuance']['enabled'] === true) {
210-
$loader->load('web_token_issuance.xml');
210+
$loader->load('web_token_issuance.php');
211211
$accessTokenBuilder = 'lexik_jwt_authentication.access_token_builder';
212212
$accessTokenBuilderDefinition = $container->getDefinition($accessTokenBuilder);
213213
$accessTokenBuilderDefinition
@@ -223,7 +223,7 @@ private function processWithWebTokenConfig(array $config, ContainerBuilder $cont
223223
}
224224
}
225225
if ($config['access_token_verification']['enabled'] === true) {
226-
$loader->load('web_token_verification.xml');
226+
$loader->load('web_token_verification.php');
227227
$accessTokenLoader = 'lexik_jwt_authentication.access_token_loader';
228228
$accessTokenLoaderDefinition = $container->getDefinition($accessTokenLoader);
229229
$accessTokenLoaderDefinition
@@ -241,6 +241,14 @@ private function processWithWebTokenConfig(array $config, ContainerBuilder $cont
241241
->replaceArgument(11, $config['access_token_verification']['encryption']['allowed_content_encryption_algorithms'])
242242
->replaceArgument(12, $config['access_token_verification']['encryption']['keyset'])
243243
;
244+
} else {
245+
$accessTokenLoaderDefinition
246+
->replaceArgument(8, null)
247+
->replaceArgument(9, null)
248+
->replaceArgument(10, null)
249+
->replaceArgument(11, null)
250+
->replaceArgument(12, null)
251+
;
244252
}
245253
}
246254
}

Resources/config/api_platform.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Lexik\Bundle\JWTAuthenticationBundle\OpenApi\OpenApiFactory;
6+
use Symfony\Component\DependencyInjection\ContainerInterface;
7+
8+
return static function (ContainerConfigurator $container) {
9+
$services = $container->services();
10+
11+
$services->set('lexik_jwt_authentication.api_platform.openapi.factory', OpenApiFactory::class)
12+
->private()
13+
->decorate('api_platform.openapi.factory', null, 0, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)
14+
->args([
15+
service('lexik_jwt_authentication.api_platform.openapi.factory.inner'),
16+
'', // check path
17+
'', // username path
18+
'', // password path
19+
]);
20+
};

Resources/config/api_platform.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Lexik\Bundle\JWTAuthenticationBundle\EventListener\BlockJWTListener;
6+
use Lexik\Bundle\JWTAuthenticationBundle\EventListener\RejectBlockedTokenListener;
7+
use Lexik\Bundle\JWTAuthenticationBundle\Services\BlockedToken\CacheItemPoolBlockedTokenManager;
8+
use Lexik\Bundle\JWTAuthenticationBundle\Services\BlockedTokenManagerInterface;
9+
use Symfony\Component\Security\Http\Event\LoginFailureEvent;
10+
use Symfony\Component\Security\Http\Event\LogoutEvent;
11+
12+
return static function (ContainerConfigurator $container) {
13+
$services = $container->services();
14+
15+
$services->set('lexik_jwt_authentication.event_listener.block_jwt_listener', BlockJWTListener::class)
16+
->args([
17+
service('lexik_jwt_authentication.blocked_token_manager'),
18+
service('lexik_jwt_authentication.extractor.chain_extractor'),
19+
service('lexik_jwt_authentication.jwt_manager'),
20+
])
21+
->tag('kernel.event_listener', ['event' => LoginFailureEvent::class, 'method' => 'onLoginFailure', 'dispatcher' => 'event_dispatcher'])
22+
->tag('kernel.event_listener', ['event' => LogoutEvent::class, 'method' => 'onLogout', 'dispatcher' => 'event_dispatcher']);
23+
24+
$services->set('lexik_jwt_authentication.event_listener.reject_blocked_token_listener', RejectBlockedTokenListener::class)
25+
->args([service('lexik_jwt_authentication.blocked_token_manager')])
26+
->tag('kernel.event_listener', ['event' => 'lexik_jwt_authentication.on_jwt_authenticated']);
27+
28+
$services->set('lexik_jwt_authentication.blocked_token_manager', CacheItemPoolBlockedTokenManager::class)
29+
->args([service('lexik_jwt_authentication.blocklist_token.cache')]);
30+
31+
$services->alias(BlockedTokenManagerInterface::class, 'lexik_jwt_authentication.blocked_token_manager');
32+
};

Resources/config/blocklist_token.xml

Lines changed: 0 additions & 28 deletions
This file was deleted.

Resources/config/console.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
4+
5+
use Lexik\Bundle\JWTAuthenticationBundle\Command\CheckConfigCommand;
6+
use Lexik\Bundle\JWTAuthenticationBundle\Command\EnableEncryptionConfigCommand;
7+
use Lexik\Bundle\JWTAuthenticationBundle\Command\GenerateKeyPairCommand;
8+
use Lexik\Bundle\JWTAuthenticationBundle\Command\GenerateTokenCommand;
9+
use Lexik\Bundle\JWTAuthenticationBundle\Command\MigrateConfigCommand;
10+
11+
return static function (ContainerConfigurator $container) {
12+
$services = $container->services();
13+
14+
$services->set('lexik_jwt_authentication.check_config_command', CheckConfigCommand::class)
15+
->args([
16+
service('lexik_jwt_authentication.key_loader'),
17+
'%lexik_jwt_authentication.encoder.signature_algorithm%',
18+
])
19+
->tag('console.command', ['command' => 'lexik:jwt:check-config']);
20+
21+
$services->set('lexik_jwt_authentication.migrate_config_command', MigrateConfigCommand::class)
22+
->args([
23+
service('lexik_jwt_authentication.key_loader'),
24+
'%lexik_jwt_authentication.pass_phrase%',
25+
'%lexik_jwt_authentication.encoder.signature_algorithm%',
26+
])
27+
->tag('console.command', ['command' => 'lexik:jwt:migrate-config']);
28+
29+
$services->set('lexik_jwt_authentication.enable_encryption_config_command', EnableEncryptionConfigCommand::class)
30+
->args([service('Jose\Component\Core\AlgorithmManagerFactory')->nullOnInvalid()])
31+
->tag('console.command', ['command' => 'lexik:jwt:enable-encryption']);
32+
33+
$services->set('lexik_jwt_authentication.generate_token_command', GenerateTokenCommand::class)
34+
->public()
35+
->args([
36+
service('lexik_jwt_authentication.jwt_manager'),
37+
[], // user providers
38+
])
39+
->tag('console.command', ['command' => 'lexik:jwt:generate-token']);
40+
41+
$services->set('lexik_jwt_authentication.generate_keypair_command', GenerateKeyPairCommand::class)
42+
->args([
43+
service('filesystem'),
44+
'',
45+
'',
46+
'',
47+
'',
48+
])
49+
->tag('console.command', ['command' => 'lexik:jwt:generate-keypair']);
50+
};

0 commit comments

Comments
 (0)