diff --git a/DependencyInjection/Compiler/RegisterLegacyGuardAuthenticatorPass.php b/DependencyInjection/Compiler/RegisterLegacyGuardAuthenticatorPass.php new file mode 100644 index 00000000..ad88626b --- /dev/null +++ b/DependencyInjection/Compiler/RegisterLegacyGuardAuthenticatorPass.php @@ -0,0 +1,33 @@ +hasParameter('lexik_jwt_authentication.authenticator_manager_enabled') || !$container->getParameter('lexik_jwt_authentication.authenticator_manager_enabled')) { + return; + } + + $container->register('.lexik_jwt_authentication.pre_authentication_token_storage', TokenStorage::class); + $container + ->register('lexik_jwt_authentication.security.guard.jwt_token_authenticator', JWTTokenAuthenticator::class) + ->setArguments([ + new Reference('lexik_jwt_authentication.jwt_manager'), + new Reference('event_dispatcher'), + new Reference('lexik_jwt_authentication.extractor.chain_extractor'), + new Reference('.lexik_jwt_authentication.pre_authentication_token_storage'), + ]) + ; + $container->setAlias('lexik_jwt_authentication.jwt_token_authenticator', 'lexik_jwt_authentication.security.guard.jwt_token_authenticator'); + $container->getParameterBag()->remove('lexik_jwt_authentication.authenticator_manager_enabled'); + } +} + diff --git a/DependencyInjection/Security/Factory/JWTUserFactory.php b/DependencyInjection/Security/Factory/JWTUserFactory.php index ef70cf8a..1e850b12 100644 --- a/DependencyInjection/Security/Factory/JWTUserFactory.php +++ b/DependencyInjection/Security/Factory/JWTUserFactory.php @@ -22,6 +22,10 @@ public function create(ContainerBuilder $container, $id, $config) { $container->setDefinition($id, new ChildDefinition('lexik_jwt_authentication.security.jwt_user_provider')) ->replaceArgument(0, $config['class']); + + // Compile-time parameter removed by RemoveLegacyAuthenticatorPass + // Stop setting it when guard support gets removed (aka when removing Symfony<5.3 support) + $container->setParameter('lexik_jwt_authentication.authenticator_manager_enabled', true); } public function getKey() diff --git a/LexikJWTAuthenticationBundle.php b/LexikJWTAuthenticationBundle.php index e8348d66..20a39a3c 100644 --- a/LexikJWTAuthenticationBundle.php +++ b/LexikJWTAuthenticationBundle.php @@ -2,6 +2,7 @@ namespace Lexik\Bundle\JWTAuthenticationBundle; +use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\RegisterLegacyGuardAuthenticatorPass; use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler\WireGenerateTokenCommandPass; use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTAuthenticatorFactory; use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTFactory; @@ -27,6 +28,7 @@ public function build(ContainerBuilder $container) parent::build($container); $container->addCompilerPass(new WireGenerateTokenCommandPass()); + $container->addCompilerPass(new RegisterLegacyGuardAuthenticatorPass()); /** @var SecurityExtension $extension */ $extension = $container->getExtension('security'); diff --git a/Resources/config/token_authenticator.xml b/Resources/config/token_authenticator.xml index 9b03a35d..75a5ef6a 100644 --- a/Resources/config/token_authenticator.xml +++ b/Resources/config/token_authenticator.xml @@ -5,17 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - - - - - - - - -