Skip to content

Commit

Permalink
SSO: Add new user to access url after OAuth2 process - refs BT#21881
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Aug 26, 2024
1 parent 9c92565 commit 3c8f1d0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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;
Expand Down Expand Up @@ -35,6 +36,7 @@ public function __construct(
protected readonly RouterInterface $router,
protected readonly UserRepository $userRepository,
protected readonly AuthenticationConfigHelper $authenticationConfigHelper,
protected readonly AccessUrlHelper $urlHelper,
) {
$this->client = $this->clientRegistry->getClient($this->providerName);
}
Expand Down Expand Up @@ -76,5 +78,8 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
return new Response($message, Response::HTTP_FORBIDDEN);
}

/**
* Find or create and save the new user.
*/
abstract protected function userLoader(AccessToken $accessToken): User;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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;
Expand All @@ -25,9 +26,16 @@ public function __construct(
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
Expand Down Expand Up @@ -61,7 +69,9 @@ protected function userLoader(AccessToken $accessToken): User
;

$this->userRepository->updateUser($user);
// updateAccessUrls ?

$url = $this->urlHelper->getCurrent();
$url->addUser($user);

return $user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -34,14 +35,16 @@ public function __construct(
RouterInterface $router,
UserRepository $userRepository,
AuthenticationConfigHelper $authenticationConfigHelper,
AccessUrlHelper $urlHelper,
protected readonly ExtraFieldRepository $extraFieldRepository,
protected readonly ExtraFieldValuesRepository $extraFieldValuesRepository,
) {
parent::__construct(
$clientRegistry,
$router,
$userRepository,
$authenticationConfigHelper
$authenticationConfigHelper,
$urlHelper,
);
}

Expand Down Expand Up @@ -161,7 +164,9 @@ public function saveUserInfo(User $user, array $resourceOwnerData, array $provid
;

$this->userRepository->updateUser($user);
// updateAccessUrls ?

$url = $this->urlHelper->getCurrent();
$url->addUser($user);
}

private function getUserStatus(array $resourceOwnerData, int $defaultStatus, array $providerParams): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ protected function userLoader(AccessToken $accessToken): User
;

$this->userRepository->updateUser($user);
// updateAccessUrls ?

$url = $this->urlHelper->getCurrent();
$url->addUser($user);

return $user;
}
Expand Down

0 comments on commit 3c8f1d0

Please sign in to comment.