Skip to content

Commit 0cd551b

Browse files
authored
Merge pull request #29 from moufmouf/multiple_providers
Login mutation does not appear if multiple providers are defined
2 parents 22b829f + 5d42441 commit 0cd551b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

DependencyInjection/GraphqliteCompilerPass.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public function process(ContainerBuilder $container)
8686
$controllersNamespaces = $container->getParameter('graphqlite.namespace.controllers');
8787
$typesNamespaces = $container->getParameter('graphqlite.namespace.types');
8888

89+
$firewallName = $container->getParameter('graphqlite.security.firewall_name');
90+
$firewallConfigServiceName = 'security.firewall.map.config.'.$firewallName;
91+
8992
// 2 seconds of TTL in environment mode. Otherwise, let's cache forever!
9093

9194
$schemaFactory = $container->getDefinition(SchemaFactory::class);
@@ -99,7 +102,7 @@ public function process(ContainerBuilder $container)
99102

100103
$disableLogin = false;
101104
if ($container->getParameter('graphqlite.security.enable_login') === 'auto'
102-
&& (!$container->has(UserProviderInterface::class) ||
105+
&& (!$container->has($firewallConfigServiceName) ||
103106
!$container->has(UserPasswordEncoderInterface::class) ||
104107
!$container->has(TokenStorageInterface::class) ||
105108
!$container->has(SessionInterface::class)
@@ -119,11 +122,18 @@ public function process(ContainerBuilder $container)
119122
if (!$container->has(SessionInterface::class)) {
120123
throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to enable session support (via the "framework.session.enabled" config parameter).');
121124
}
122-
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has(UserProviderInterface::class)) {
125+
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has($firewallConfigServiceName)) {
123126
throw new GraphQLException('In order to enable the login/logout mutations (via the graphqlite.security.enable_login parameter), you need to install the security bundle. Please be sure to correctly configure the user provider (in the security.providers configuration settings)');
124127
}
125128
}
126129

130+
if ($disableLogin === false) {
131+
// Let's do some dark magic. We need the user provider. We need its name. It is stored in the "config" object.
132+
$provider = $container->findDefinition('security.firewall.map.config.'.$firewallName)->getArgument(5);
133+
134+
$container->findDefinition(LoginController::class)->setArgument(0, new Reference($provider));
135+
}
136+
127137

128138
foreach ($container->getDefinitions() as $id => $definition) {
129139
if ($definition->isAbstract() || $definition->getClass() === null) {

Tests/GraphqliteTestingKernel.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,21 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
7979
],
8080
],
8181
],
82+
'in_memory_other' => [
83+
'memory' => [
84+
'users' => [
85+
'foo' => [
86+
'password' => 'bar',
87+
'roles' => 'ROLE_USER',
88+
],
89+
],
90+
],
91+
],
8292
],
8393
'firewalls' => [
8494
'main' => [
85-
'anonymous' => true
95+
'anonymous' => true,
96+
'provider' => 'in_memory'
8697
]
8798
],
8899
'encoders' => [

0 commit comments

Comments
 (0)