Skip to content

Login mutation does not appear if multiple providers are defined #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions DependencyInjection/GraphqliteCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function process(ContainerBuilder $container)
$controllersNamespaces = $container->getParameter('graphqlite.namespace.controllers');
$typesNamespaces = $container->getParameter('graphqlite.namespace.types');

$firewallName = $container->getParameter('graphqlite.security.firewall_name');
$firewallConfigServiceName = 'security.firewall.map.config.'.$firewallName;

// 2 seconds of TTL in environment mode. Otherwise, let's cache forever!

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

$disableLogin = false;
if ($container->getParameter('graphqlite.security.enable_login') === 'auto'
&& (!$container->has(UserProviderInterface::class) ||
&& (!$container->has($firewallConfigServiceName) ||
!$container->has(UserPasswordEncoderInterface::class) ||
!$container->has(TokenStorageInterface::class) ||
!$container->has(SessionInterface::class)
Expand All @@ -119,11 +122,18 @@ public function process(ContainerBuilder $container)
if (!$container->has(SessionInterface::class)) {
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).');
}
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has(UserProviderInterface::class)) {
if (!$container->has(UserPasswordEncoderInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has($firewallConfigServiceName)) {
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)');
}
}

if ($disableLogin === false) {
// Let's do some dark magic. We need the user provider. We need its name. It is stored in the "config" object.
$provider = $container->findDefinition('security.firewall.map.config.'.$firewallName)->getArgument(5);

$container->findDefinition(LoginController::class)->setArgument(0, new Reference($provider));
}


foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->isAbstract() || $definition->getClass() === null) {
Expand Down
13 changes: 12 additions & 1 deletion Tests/GraphqliteTestingKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
],
],
],
'in_memory_other' => [
'memory' => [
'users' => [
'foo' => [
'password' => 'bar',
'roles' => 'ROLE_USER',
],
],
],
],
],
'firewalls' => [
'main' => [
'anonymous' => true
'anonymous' => true,
'provider' => 'in_memory'
]
],
'encoders' => [
Expand Down