Skip to content

Commit 08696ff

Browse files
committed
SSO: Fix adding user in url - refs BT#21881
1 parent b725e2b commit 08696ff

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/CoreBundle/Security/Authenticator/OAuth2/AbstractAuthenticator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Chamilo\CoreBundle\Repository\Node\UserRepository;
1111
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
1212
use Chamilo\CoreBundle\ServiceHelper\AuthenticationConfigHelper;
13+
use Doctrine\ORM\EntityManagerInterface;
1314
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
1415
use KnpU\OAuth2ClientBundle\Client\OAuth2ClientInterface;
1516
use KnpU\OAuth2ClientBundle\Security\Authenticator\OAuth2Authenticator;
@@ -37,6 +38,7 @@ public function __construct(
3738
protected readonly UserRepository $userRepository,
3839
protected readonly AuthenticationConfigHelper $authenticationConfigHelper,
3940
protected readonly AccessUrlHelper $urlHelper,
41+
protected readonly EntityManagerInterface $entityManager,
4042
) {
4143
$this->client = $this->clientRegistry->getClient($this->providerName);
4244
}

src/CoreBundle/Security/Authenticator/OAuth2/FacebookAuthenticator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
1212
use Chamilo\CoreBundle\ServiceHelper\AuthenticationConfigHelper;
1313
use Cocur\Slugify\SlugifyInterface;
14+
use Doctrine\ORM\EntityManagerInterface;
1415
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
1516
use League\OAuth2\Client\Provider\FacebookUser;
1617
use League\OAuth2\Client\Token\AccessToken;
@@ -27,6 +28,7 @@ public function __construct(
2728
UserRepository $userRepository,
2829
AuthenticationConfigHelper $authenticationConfigHelper,
2930
AccessUrlHelper $urlHelper,
31+
EntityManagerInterface $entityManager,
3032
protected readonly SlugifyInterface $slugify,
3133
) {
3234
parent::__construct(
@@ -35,6 +37,7 @@ public function __construct(
3537
$userRepository,
3638
$authenticationConfigHelper,
3739
$urlHelper,
40+
$entityManager,
3841
);
3942
}
4043

@@ -73,6 +76,8 @@ protected function userLoader(AccessToken $accessToken): User
7376
$url = $this->urlHelper->getCurrent();
7477
$url->addUser($user);
7578

79+
$this->entityManager->flush();
80+
7681
return $user;
7782
}
7883

src/CoreBundle/Security/Authenticator/OAuth2/GenericAuthenticator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ public function __construct(
4040
UserRepository $userRepository,
4141
AuthenticationConfigHelper $authenticationConfigHelper,
4242
AccessUrlHelper $urlHelper,
43+
EntityManagerInterface $entityManager,
4344
protected readonly ExtraFieldRepository $extraFieldRepository,
4445
protected readonly ExtraFieldValuesRepository $extraFieldValuesRepository,
4546
protected readonly AccessUrlRepository $accessUrlRepository,
46-
protected readonly EntityManagerInterface $entityManager,
4747
) {
4848
parent::__construct(
4949
$clientRegistry,
5050
$router,
5151
$userRepository,
5252
$authenticationConfigHelper,
5353
$urlHelper,
54+
$entityManager,
5455
);
5556
}
5657

@@ -177,6 +178,8 @@ public function saveUserInfo(User $user, array $resourceOwnerData, array $provid
177178

178179
$url = $this->urlHelper->getCurrent();
179180
$url->addUser($user);
181+
182+
$this->entityManager->flush();
180183
}
181184

182185
private function getUserStatus(array $resourceOwnerData, int $defaultStatus, array $providerParams): int

src/CoreBundle/Security/Authenticator/OAuth2/KeycloakAuthenticator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ protected function userLoader(AccessToken $accessToken): User
5353
$url = $this->urlHelper->getCurrent();
5454
$url->addUser($user);
5555

56+
$this->entityManager->flush();
57+
5658
return $user;
5759
}
5860
}

0 commit comments

Comments
 (0)