Skip to content

Commit 30b688e

Browse files
authored
Merge pull request #130 from andrew-demb/fix-tests
Fix working with session
2 parents 972bbfb + 89e3538 commit 30b688e

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
install-args: ['', '--prefer-lowest']
15-
php-version: ['7.2', '7.3', '7.4', '8.0']
15+
php-version: ['7.4', '8.0']
1616
fail-fast: false
1717
steps:
1818
# Cancel previous runs of the same branch

Controller/GraphQL/LoginController.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
use RuntimeException;
66
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
77
use Symfony\Component\HttpFoundation\Request;
8-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
98
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
109
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1110
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
12-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1311
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1412
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
1513
use Symfony\Component\Security\Core\User\UserInterface;
@@ -36,22 +34,17 @@ class LoginController
3634
* @var string
3735
*/
3836
private $firewallName;
39-
/**
40-
* @var SessionInterface
41-
*/
42-
private $session;
4337
/**
4438
* @var EventDispatcherInterface
4539
*/
4640
private $eventDispatcher;
4741

48-
public function __construct(UserProviderInterface $userProvider, UserPasswordHasherInterface $passwordEncoder, TokenStorageInterface $tokenStorage, SessionInterface $session, EventDispatcherInterface $eventDispatcher, string $firewallName)
42+
public function __construct(UserProviderInterface $userProvider, UserPasswordHasherInterface $passwordEncoder, TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher, string $firewallName)
4943
{
5044
$this->userProvider = $userProvider;
5145
$this->passwordEncoder = $passwordEncoder;
5246
$this->tokenStorage = $tokenStorage;
5347
$this->firewallName = $firewallName;
54-
$this->session = $session;
5548
$this->eventDispatcher = $eventDispatcher;
5649
}
5750

@@ -83,8 +76,8 @@ public function login(string $userName, string $password, Request $request): Use
8376
$this->tokenStorage->setToken($token);
8477

8578
// If the firewall name is not main, then the set value would be instead:
86-
// $this->get('session')->set('_security_XXXFIREWALLNAMEXXX', serialize($token));
87-
$this->session->set('_security_'.$this->firewallName, serialize($token));
79+
// $request->getSession()->set('_security_XXXFIREWALLNAMEXXX', serialize($token));
80+
$request->getSession()->set('_security_'.$this->firewallName, serialize($token));
8881

8982
// Fire the login event manually
9083
$event = new InteractiveLoginEvent($request, $token);
@@ -97,11 +90,11 @@ public function login(string $userName, string $password, Request $request): Use
9790
/**
9891
* @Mutation()
9992
*/
100-
public function logout(): bool
93+
public function logout(Request $request): bool
10194
{
10295
$this->tokenStorage->setToken(null);
10396

104-
$this->session->remove('_security_'.$this->firewallName);
97+
$request->getSession()->remove('_security_'.$this->firewallName);
10598

10699
return true;
107100
}

DependencyInjection/GraphQLiteCompilerPass.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use Symfony\Component\DependencyInjection\ContainerBuilder;
3333
use Symfony\Component\DependencyInjection\Definition;
3434
use Symfony\Component\DependencyInjection\Reference;
35-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
3635
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
3736
use Symfony\Component\Security\Core\User\UserInterface;
3837
use TheCodingMachine\CacheUtils\ClassBoundCache;
@@ -106,7 +105,7 @@ public function process(ContainerBuilder $container): void
106105
&& (!$container->has($firewallConfigServiceName) ||
107106
!$container->has(UserPasswordHasherInterface::class) ||
108107
!$container->has(TokenStorageInterface::class) ||
109-
!$container->has(SessionInterface::class)
108+
!$container->has('session.factory')
110109
)) {
111110
$disableLogin = true;
112111
}
@@ -119,7 +118,7 @@ public function process(ContainerBuilder $container): void
119118
}
120119

121120
if ($container->getParameter('graphqlite.security.enable_login') === 'on') {
122-
if (!$container->has(SessionInterface::class)) {
121+
if (!$container->has('session.factory')) {
123122
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).');
124123
}
125124
if (!$container->has(UserPasswordHasherInterface::class) || !$container->has(TokenStorageInterface::class) || !$container->has($firewallConfigServiceName)) {

0 commit comments

Comments
 (0)