Skip to content
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

New clients keys and routes name to avoid conflict with knpu base key… #18

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/GoogleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([], []);
}

/**
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/MicrosoftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Factory/OauthClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand All @@ -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'
);
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Authenticator/OauthAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions templates/google_auth_button.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
<div style="margin: 0.5rem 0 0.5rem 0">
<script src="https://accounts.google.com/gsi/client" async defer></script>

<div id="g_id_onload"
data-client_id="{{ google_client_id }}"
data-login_uri="{{ path('connect_google') }}">
data-login_uri="{{ path('connect_admin_google') }}">
</div>
<div class="g_id_signin"
data-type="standard"
Expand Down
2 changes: 1 addition & 1 deletion templates/microsoft_auth_button.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% if microsoft_client_id is not null %}
<div style="margin: 0.5rem 0 0.5rem 0; align-items: center">
<button style="padding:8px; background-color: white; width: 100%; border: 1px lightgray solid; border-radius: 4px; height: 2.8rem;" disabled>
<a href="{{ path('connect_azure') }}" style="width: 100%; display: flex; color: black; font-size: 1rem; justify-content: center; font-weight: lighter">
<a href="{{ path('connect_admin_azure') }}" style="width: 100%; display: flex; color: black; font-size: 1rem; justify-content: center; font-weight: lighter">
<img style="margin-right: .5rem;" src="https://learn.microsoft.com/fr-fr/azure/active-directory/develop/media/howto-add-branding-in-apps/ms-symbollockup_mssymbol_19.png" alt="microsoft icon">
<span style="">{{ "sylius.authentication.admin.microsoft_login_button_label"|trans }}</span>
</a>
Expand Down