Skip to content

Commit

Permalink
bug #58 Fix authenticator registration with multiple user providers (…
Browse files Browse the repository at this point in the history
…chalasr)

This PR was merged into the 0.1-dev branch.

Discussion
----------

Fix authenticator registration with multiple user providers

Fixes #41

Commits
-------

92eec1c Fix authenticator registration with multiple user providers
  • Loading branch information
chalasr committed Nov 2, 2021
2 parents d9e7d7f + 92eec1c commit 699c99c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/DependencyInjection/Security/OAuth2Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* @author Mathias Arlaud <[email protected]>
Expand All @@ -21,10 +22,14 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.');
}

public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProvider): string
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
{
$authenticator = sprintf('security.authenticator.oauth2.%s', $firewallName);
$container->setDefinition($authenticator, new ChildDefinition(OAuth2Authenticator::class));

$definition = new ChildDefinition(OAuth2Authenticator::class);
$definition->replaceArgument(2, new Reference($userProviderId));

$container->setDefinition($authenticator, $definition);

return $authenticator;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;
Expand Down Expand Up @@ -55,7 +56,6 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserProviderInterface;

return static function (ContainerConfigurator $container): void {
$container->services()
Expand Down Expand Up @@ -118,8 +118,8 @@
->args([
service('league.oauth2_server.factory.psr_http'),
service(ResourceServer::class),
service(UserProviderInterface::class),
null,
abstract_arg('User Provider'),
abstract_arg('Role prefix'),
])
->alias(OAuth2Authenticator::class, 'league.oauth2_server.authenticator.oauth2')

Expand Down
10 changes: 10 additions & 0 deletions tests/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
'enable_authenticator_manager' => true,
'firewalls' => [
'test' => [
'provider' => 'in_memory',
'pattern' => '^/security-test',
'stateless' => true,
'oauth2' => true,
Expand All @@ -123,6 +124,15 @@ public function registerContainerConfiguration(LoaderInterface $loader)
],
],
],
'another_provider' => [
'memory' => [
'users' => [
FixtureFactory::FIXTURE_USER => [
'roles' => ['ROLE_USER'],
],
],
],
],
],
]);

Expand Down

0 comments on commit 699c99c

Please sign in to comment.