Skip to content

Commit

Permalink
feature #925 Allow to set provider in jwt authenticator. (fd6130)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

Allow to set provider in jwt authenticator.

Fix #892

Allow to set provider in `jwt` authenticator.

Commits
-------

5b995fb Allow to set provider in jwt authenticator.
  • Loading branch information
chalasr committed Oct 24, 2021
2 parents c6ba7c7 + 5b995fb commit 9e32ce2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions Resources/doc/1-configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9e32ce2

Please sign in to comment.