diff --git a/DependencyInjection/Security/Factory/JWTAuthenticatorFactory.php b/DependencyInjection/Security/Factory/JWTAuthenticatorFactory.php index e1d5352a..293cd5d5 100644 --- a/DependencyInjection/Security/Factory/JWTAuthenticatorFactory.php +++ b/DependencyInjection/Security/Factory/JWTAuthenticatorFactory.php @@ -46,6 +46,9 @@ public function addConfiguration(NodeDefinition $node) { $node ->children() + ->scalarNode('provider') + ->defaultNull() + ->end() ->scalarNode('authenticator') ->defaultValue('lexik_jwt_authentication.security.jwt_authenticator') ->end() @@ -56,6 +59,9 @@ public function addConfiguration(NodeDefinition $node) public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { $authenticatorId = 'security.authenticator.jwt.'.$firewallName; + + $userProviderId = empty($config['provider']) ? $userProviderId : 'security.user.provider.concrete.' . $config['provider']; + $container ->setDefinition($authenticatorId, new ChildDefinition($config['authenticator'])) ->replaceArgument(3, new Reference($userProviderId)) diff --git a/Resources/doc/1-configuration-reference.md b/Resources/doc/1-configuration-reference.md index 72845438..1018c8c3 100644 --- a/Resources/doc/1-configuration-reference.md +++ b/Resources/doc/1-configuration-reference.md @@ -160,7 +160,13 @@ security: api: # ... jwt: ~ # enables the jwt authenticator + + # Full config with defaults: + # jwt: + # provider: null (you can put provider here or just ignore this config) + # authenticator: lexik_jwt_authentication.security.jwt_authenticator (default jwt authenticator) # ... + ``` For Symfony versions prior to 5.3, use the Guard authenticator: