-
Notifications
You must be signed in to change notification settings - Fork 531
OAuth2 #5753
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
OAuth2 #5753
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d71542d
Add methods to find extra field and its values from entity repository…
AngelFQC 21d5f05
SSO: Implement generic OAuth2 login/registration - refs BT#21881
AngelFQC 007d59d
Vendor: SSO: Add league/oauth2-facebook + implement facebook login/re…
AngelFQC 2270761
Vendor: SSO: Add stevenmaguire/oauth2-keycloak + implement keycloak l…
AngelFQC fed229c
Vendor: Update composer.lock
AngelFQC 4c930fe
Minor: Format code - refs BT#21881
AngelFQC 789a347
SSO: Allow default authentication params for all URLs - refs BT#21881
AngelFQC 2211649
SSO: Add new user to access url after OAuth2 process - refs BT#21881
AngelFQC a03d7c1
SSO: Allow to update access urls for user in generic oauth2 - refs BT…
AngelFQC 23e182a
SSO: Display: External logins under below the login form - refs BT#21881
AngelFQC 3aa77ce
Merge branch 'master' into BT21881
NicoDucou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Vendor: SSO: Add stevenmaguire/oauth2-keycloak + implement keycloak l…
…ogin/registration - refs BT#21881
- Loading branch information
commit 227076163d63cc37f08494cb4266ee4b6c79d2cb
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/CoreBundle/Controller/OAuth2/KeycloakProviderController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php | ||
|
|
||
| /* For licensing terms, see /license.txt */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Chamilo\CoreBundle\Controller\OAuth2; | ||
|
|
||
| use Chamilo\CoreBundle\ServiceHelper\AuthenticationConfigHelper; | ||
| use KnpU\OAuth2ClientBundle\Client\ClientRegistry; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\Routing\Attribute\Route; | ||
|
|
||
| class KeycloakProviderController extends AbstractProviderController | ||
| { | ||
| #[Route('/connect/keycloak', name: 'chamilo.oauth2_keycloak_start')] | ||
| public function connect( | ||
| ClientRegistry $clientRegistry, | ||
| AuthenticationConfigHelper $authenticationConfigHelper, | ||
| ): Response { | ||
| return $this->getStartResponse('keycloak', $clientRegistry, $authenticationConfigHelper); | ||
| } | ||
|
|
||
| #[Route('/connect/keycloak/check', name: 'chamilo.oauth2_keycloak_check')] | ||
| public function connectCheck(): void {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| use League\OAuth2\Client\Provider\AbstractProvider; | ||
| use League\OAuth2\Client\Provider\Facebook; | ||
| use League\OAuth2\Client\Provider\GenericProvider; | ||
| use Stevenmaguire\OAuth2\Client\Provider\Keycloak; | ||
| use Symfony\Component\DependencyInjection\Attribute\AsDecorator; | ||
| use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated; | ||
|
|
||
|
|
@@ -35,6 +36,7 @@ public function createProvider( | |
| $options = match ($class) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space before opening parenthesis of function call prohibited |
||
| GenericProvider::class => $this->getProviderOptions('generic'), | ||
| Facebook::class => $this->getProviderOptions('facebook'), | ||
| Keycloak::class => $this->getProviderOptions('keycloak'), | ||
| }; | ||
|
|
||
| return $this->inner->createProvider($class, $options, $redirectUri, $redirectParams, $collaborators); | ||
|
|
||
57 changes: 57 additions & 0 deletions
57
src/CoreBundle/Security/Authenticator/OAuth2/KeycloakAuthenticator.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| /* For licensing terms, see /license.txt */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Chamilo\CoreBundle\Security\Authenticator\OAuth2; | ||
|
|
||
| use Chamilo\CoreBundle\Entity\User; | ||
| use KnpU\OAuth2ClientBundle\Client\OAuth2ClientInterface; | ||
| use League\OAuth2\Client\Token\AccessToken; | ||
| use Stevenmaguire\OAuth2\Client\Provider\KeycloakResourceOwner; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| class KeycloakAuthenticator extends AbstractAuthenticator | ||
| { | ||
| protected string $providerName = 'keycloak'; | ||
|
|
||
| public function supports(Request $request): ?bool | ||
| { | ||
| return 'chamilo.oauth2_keycloak_check' === $request->attributes->get('_route'); | ||
| } | ||
|
|
||
| protected function userLoader(AccessToken $accessToken): User | ||
| { | ||
| /** @var KeycloakResourceOwner $resourceOwner */ | ||
| $resourceOwner = $this->client->fetchUserFromToken($accessToken); | ||
|
|
||
| $user = $this->userRepository->findOneBy(['username' => $resourceOwner->getUsername()]) | ||
| ?: | ||
| $this->userRepository->findOneBy(['username' => $resourceOwner->getId()]); | ||
|
|
||
| if (!$user) { | ||
| $user = (new User()) | ||
| ->setCreatorId($this->userRepository->getRootUser()->getId()) | ||
| ; | ||
| } | ||
|
|
||
| $username = $resourceOwner->getUsername() ?: $resourceOwner->getId(); | ||
|
|
||
| $user | ||
| ->setFirstname($resourceOwner->getFirstName()) | ||
| ->setLastname($resourceOwner->getLastName()) | ||
| ->setEmail($resourceOwner->getEmail()) | ||
| ->setUsername($username) | ||
| ->setPlainPassword('keycloak') | ||
| ->setStatus(STUDENT) | ||
| ->setAuthSource('keycloak') | ||
| ->setRoleFromStatus(STUDENT) | ||
| ; | ||
|
|
||
| $this->userRepository->updateUser($user); | ||
| // updateAccessUrls ? | ||
|
|
||
| return $user; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before opening parenthesis of function call prohibited