From 4e11db4511dd519c9122b4471868d4de96e9e5fc Mon Sep 17 00:00:00 2001 From: "tim.messaoudene" Date: Mon, 15 Jan 2024 11:38:02 +0100 Subject: [PATCH] New clients keys and routes name to avoid conflict with knpu base keys/routes --- config/app.yaml | 8 ++++---- src/Controller/GoogleController.php | 6 +++--- src/Controller/MicrosoftController.php | 6 +++--- src/Factory/OauthClientFactory.php | 8 ++++---- src/Security/Authenticator/OauthAuthenticator.php | 4 ++-- templates/google_auth_button.html.twig | 4 +--- templates/microsoft_auth_button.html.twig | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/config/app.yaml b/config/app.yaml index 080e236..5f1ec48 100644 --- a/config/app.yaml +++ b/config/app.yaml @@ -13,17 +13,17 @@ twig: knpu_oauth2_client: clients: - google_main: + google_admin: type: google client_id: '%env(default::OAUTH_GOOGLE_CLIENT_ID)%' client_secret: '%env(default::OAUTH_GOOGLE_CLIENT_SECRET)%' - redirect_route: 'connect_google_check' + redirect_route: 'connect_admin_google_check' redirect_params: {} - azure_main: + azure_admin: type: azure client_id: '%env(default::OAUTH_MICROSOFT_CLIENT_ID)%' client_secret: '%env(default::OAUTH_MICROSOFT_CLIENT_SECRET)%' - redirect_route: 'connect_microsoft_check' + redirect_route: 'connect_admin_microsoft_check' redirect_params: {} #TODO: a faire dans le plugin diff --git a/src/Controller/GoogleController.php b/src/Controller/GoogleController.php index 2165008..6275105 100644 --- a/src/Controller/GoogleController.php +++ b/src/Controller/GoogleController.php @@ -12,10 +12,10 @@ final class GoogleController extends AbstractController { - #[Route('/connect/google', name: 'connect_google')] + #[Route('/connect/google', name: 'connect_admin_google')] public function connectAction(ClientRegistry $clientRegistry): RedirectResponse { - return $clientRegistry->getClient('google_main')->redirect([], []); + return $clientRegistry->getClient('google_admin')->redirect([], []); } /** @@ -25,7 +25,7 @@ public function connectAction(ClientRegistry $clientRegistry): RedirectResponse * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - #[Route('/connect/google/check', name: 'connect_google_check')] + #[Route('/connect/google/check', name: 'connect_admin_google_check')] public function connectCheckAction(Request $request): void { // ** if you want to *authenticate* the user, then diff --git a/src/Controller/MicrosoftController.php b/src/Controller/MicrosoftController.php index da8edb2..7a8bb0b 100644 --- a/src/Controller/MicrosoftController.php +++ b/src/Controller/MicrosoftController.php @@ -12,16 +12,16 @@ final class MicrosoftController extends AbstractController { - #[Route('connect/microsoft', name: 'connect_azure')] + #[Route('/connect/microsoft', name: 'connect_admin_azure')] public function connectAction(ClientRegistry $clientRegistry): RedirectResponse { - return $clientRegistry->getClient('azure_main')->redirect([], []); + return $clientRegistry->getClient('azure_admin')->redirect([], []); } /** * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - #[Route('/connect/microsoft/check', name: 'connect_microsoft_check')] + #[Route('/connect/microsoft/check', name: 'connect_admin_microsoft_check')] public function connectCheckAction(Request $request): void { // ** if you want to *authenticate* the user, then diff --git a/src/Factory/OauthClientFactory.php b/src/Factory/OauthClientFactory.php index d8458a1..bb13231 100644 --- a/src/Factory/OauthClientFactory.php +++ b/src/Factory/OauthClientFactory.php @@ -30,8 +30,8 @@ public static function createGoogleOauthClient(string $googleClientId): OauthCli { return self::create( $googleClientId, - 'google_main', - 'connect_google_check', + 'google_admin', + 'connect_admin_google_check', 'google', 'sylius.google_authentication.authentication_failure' ); @@ -41,8 +41,8 @@ public static function createMicrosoftOauthClient(string $microsoftClientId): Oa { return self::create( $microsoftClientId, - 'azure_main', - 'connect_microsoft_check', + 'azure_admin', + 'connect_admin_microsoft_check', 'microsoft', 'sylius.microsoft_authentication.authentication_failure' ); diff --git a/src/Security/Authenticator/OauthAuthenticator.php b/src/Security/Authenticator/OauthAuthenticator.php index 07837d7..8230dc0 100644 --- a/src/Security/Authenticator/OauthAuthenticator.php +++ b/src/Security/Authenticator/OauthAuthenticator.php @@ -75,12 +75,12 @@ public function authenticate(Request $request): Passport new UserBadge($accessToken->getToken(), function () use ($user) { Assert::isInstanceOf($this->oauthClient, OauthClient::class); $domains = $this->authorizedDomainRepository->findBy(['isEnabled' => true]); - // If there's no domains -> first use of the plugin -> connect + // If there's no domains, login with plugin is disabled... if (0 === \count($domains)) { $translatedMessage = $this->translator->trans('sylius.oauth_authentication.no_configured_domain'); throw new AuthenticationException($translatedMessage); } - // Else connect compared to authorized domains + // ...else connect compared to authorized domains foreach ($domains as $domain) { if (\array_key_exists($this->oauthClient->getProviderName(), $this->providers->availableProvidersAndControllers)) { return $this->createOauthUserIfDomainCorrespond($user, $domain); diff --git a/templates/google_auth_button.html.twig b/templates/google_auth_button.html.twig index 68a5a77..343d2b0 100644 --- a/templates/google_auth_button.html.twig +++ b/templates/google_auth_button.html.twig @@ -1,12 +1,10 @@ -{#TODO: ecrire les features du plugin dans le readme + changer les badges (license : branche master -> main) !!!!#} - {% if google_client_id is not null %}
+ data-login_uri="{{ path('connect_admin_google') }}">