SSO: Add new user to access url after OAuth2 process - refs BT#21881

pull/5753/head
Angel Fernando Quiroz Campos 3 months ago
parent 789a347d5a
commit 2211649cd8
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 5
      src/CoreBundle/Security/Authenticator/OAuth2/AbstractAuthenticator.php
  2. 14
      src/CoreBundle/Security/Authenticator/OAuth2/FacebookAuthenticator.php
  3. 9
      src/CoreBundle/Security/Authenticator/OAuth2/GenericAuthenticator.php
  4. 4
      src/CoreBundle/Security/Authenticator/OAuth2/KeycloakAuthenticator.php

@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\Security\Authenticator\OAuth2;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
use Chamilo\CoreBundle\ServiceHelper\AuthenticationConfigHelper;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use KnpU\OAuth2ClientBundle\Client\OAuth2ClientInterface;
@ -35,6 +36,7 @@ abstract class AbstractAuthenticator extends OAuth2Authenticator implements Auth
protected readonly RouterInterface $router,
protected readonly UserRepository $userRepository,
protected readonly AuthenticationConfigHelper $authenticationConfigHelper,
protected readonly AccessUrlHelper $urlHelper,
) {
$this->client = $this->clientRegistry->getClient($this->providerName);
}
@ -76,5 +78,8 @@ abstract class AbstractAuthenticator extends OAuth2Authenticator implements Auth
return new Response($message, Response::HTTP_FORBIDDEN);
}
/**
* Find or create and save the new user.
*/
abstract protected function userLoader(AccessToken $accessToken): User;
}

@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\Security\Authenticator\OAuth2;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
use Chamilo\CoreBundle\ServiceHelper\AuthenticationConfigHelper;
use Cocur\Slugify\SlugifyInterface;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
@ -25,9 +26,16 @@ class FacebookAuthenticator extends AbstractAuthenticator
RouterInterface $router,
UserRepository $userRepository,
AuthenticationConfigHelper $authenticationConfigHelper,
AccessUrlHelper $urlHelper,
protected readonly SlugifyInterface $slugify,
) {
parent::__construct($clientRegistry, $router, $userRepository, $authenticationConfigHelper);
parent::__construct(
$clientRegistry,
$router,
$userRepository,
$authenticationConfigHelper,
$urlHelper,
);
}
public function supports(Request $request): ?bool
@ -61,7 +69,9 @@ class FacebookAuthenticator extends AbstractAuthenticator
;
$this->userRepository->updateUser($user);
// updateAccessUrls ?
$url = $this->urlHelper->getCurrent();
$url->addUser($user);
return $user;
}

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\ExtraFieldRepository;
use Chamilo\CoreBundle\Repository\ExtraFieldValuesRepository;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
use Chamilo\CoreBundle\ServiceHelper\AuthenticationConfigHelper;
use ExtraField;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
@ -34,6 +35,7 @@ class GenericAuthenticator extends AbstractAuthenticator
RouterInterface $router,
UserRepository $userRepository,
AuthenticationConfigHelper $authenticationConfigHelper,
AccessUrlHelper $urlHelper,
protected readonly ExtraFieldRepository $extraFieldRepository,
protected readonly ExtraFieldValuesRepository $extraFieldValuesRepository,
) {
@ -41,7 +43,8 @@ class GenericAuthenticator extends AbstractAuthenticator
$clientRegistry,
$router,
$userRepository,
$authenticationConfigHelper
$authenticationConfigHelper,
$urlHelper,
);
}
@ -161,7 +164,9 @@ class GenericAuthenticator extends AbstractAuthenticator
;
$this->userRepository->updateUser($user);
// updateAccessUrls ?
$url = $this->urlHelper->getCurrent();
$url->addUser($user);
}
private function getUserStatus(array $resourceOwnerData, int $defaultStatus, array $providerParams): int

@ -49,7 +49,9 @@ class KeycloakAuthenticator extends AbstractAuthenticator
;
$this->userRepository->updateUser($user);
// updateAccessUrls ?
$url = $this->urlHelper->getCurrent();
$url->addUser($user);
return $user;
}

Loading…
Cancel
Save