From dd5dba17fc8727fcc4d0207f6bf14f2d260a921c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sun, 7 Dec 2025 14:32:48 +0100 Subject: [PATCH] feat: auto redirect to the SSO login page --- .env | 1 + assets/App.tsx | 2 +- assets/pages/LoginPage.tsx | 8 +++++++- assets/utils/api/index.ts | 1 + config/services.yaml | 1 + .../docs/en/install-config/configuration.mdx | 1 + .../docs/fr/install-config/configuration.mdx | 1 + src/Controller/InstanceController.php | 3 ++- src/Entity/Instance.php | 14 ++++++++++++++ 9 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.env b/.env index b46f47f..efdeff8 100644 --- a/.env +++ b/.env @@ -73,6 +73,7 @@ OAUTH_AUTHORIZATION_URL= OAUTH_TOKEN_URL= OAUTH_USERINFO_URL= OAUTH_SCOPE= +SSO_AUTO_REDIRECT=0 # Typically your IP address, this envvar is required for # some connectors that need to be provided with your host's diff --git a/assets/App.tsx b/assets/App.tsx index 1fa2da7..e7d9abc 100644 --- a/assets/App.tsx +++ b/assets/App.tsx @@ -129,7 +129,7 @@ export default function App(): React.ReactElement { }} > - }/> + }/> }/> }/> diff --git a/assets/pages/LoginPage.tsx b/assets/pages/LoginPage.tsx index 8e709ca..d546a0e 100644 --- a/assets/pages/LoginPage.tsx +++ b/assets/pages/LoginPage.tsx @@ -30,7 +30,13 @@ export default function LoginPage() { } useEffect(() => { - getConfiguration().then(setConfiguration) + getConfiguration().then((configuration) => { + if(!configuration.registerEnabled && configuration.ssoLogin && configuration.ssoAutoRedirect) { + window.location.href = '/login/oauth' + return + } + setConfiguration(configuration) + }) }, []) const grid = [ diff --git a/assets/utils/api/index.ts b/assets/utils/api/index.ts index 4b09dd5..e6aa850 100644 --- a/assets/utils/api/index.ts +++ b/assets/utils/api/index.ts @@ -105,6 +105,7 @@ export interface Watchlist { } export interface InstanceConfig { + ssoAutoRedirect: boolean ssoLogin: boolean limtedFeatures: boolean registerEnabled: boolean diff --git a/config/services.yaml b/config/services.yaml index 7c2ffea..9f7d0c6 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -9,6 +9,7 @@ parameters: mailer_sender_email: '%env(string:MAILER_SENDER_EMAIL)%' mailer_sender_name: '%env(string:MAILER_SENDER_NAME)%' oauth_enabled: '%env(OAUTH_CLIENT_ID)%' + sso_auto_redirect: '%env(bool:SSO_AUTO_REDIRECT)%' registration_enabled: '%env(bool:REGISTRATION_ENABLED)%' registration_verify_email: '%env(bool:REGISTRATION_VERIFY_EMAIL)%' diff --git a/docs/src/content/docs/en/install-config/configuration.mdx b/docs/src/content/docs/en/install-config/configuration.mdx index cd2e45f..c04cb31 100644 --- a/docs/src/content/docs/en/install-config/configuration.mdx +++ b/docs/src/content/docs/en/install-config/configuration.mdx @@ -33,6 +33,7 @@ import {LinkCard} from '@astrojs/starlight/components'; | `OAUTH_TOKEN_URL` | Token URL (OAuth 2.0) | | | `OAUTH_USERINFO_URL` | User Info URL (OAuth 2.0) | | | `OAUTH_SCOPE` | Scope (OAuth 2.0) | | +| `SSO_AUTO_REDIRECT` | Redirection to the SSO auth URL | | ## Authentication diff --git a/docs/src/content/docs/fr/install-config/configuration.mdx b/docs/src/content/docs/fr/install-config/configuration.mdx index 5249e08..1c7e81b 100644 --- a/docs/src/content/docs/fr/install-config/configuration.mdx +++ b/docs/src/content/docs/fr/install-config/configuration.mdx @@ -33,6 +33,7 @@ import {LinkCard} from '@astrojs/starlight/components'; | `OAUTH_TOKEN_URL` | URL de jeton (OAuth 2.0) | | | `OAUTH_USERINFO_URL` | URL des informations utilisateur (OAuth 2.0) | | | `OAUTH_SCOPE` | Scope (OAuth 2.0) | | +| `SSO_AUTO_REDIRECT` | Redirection vers l'URL d'authentification du SSO | | ## Authentification diff --git a/src/Controller/InstanceController.php b/src/Controller/InstanceController.php index 4ece969..7223380 100644 --- a/src/Controller/InstanceController.php +++ b/src/Controller/InstanceController.php @@ -14,7 +14,8 @@ class InstanceController extends AbstractController $instance ->setLimitedFeatures($this->getParameter('limited_features') ?? false) ->setOauthEnabled($this->getParameter('oauth_enabled') ?? false) - ->setRegisterEnabled($this->getParameter('registration_enabled') ?? false); + ->setRegisterEnabled($this->getParameter('registration_enabled') ?? false) + ->setSsoAutoRedirect($this->getParameter('sso_auto_redirect') ?? false); return $instance; } diff --git a/src/Entity/Instance.php b/src/Entity/Instance.php index d2c94be..801b9a7 100644 --- a/src/Entity/Instance.php +++ b/src/Entity/Instance.php @@ -25,6 +25,8 @@ class Instance private ?bool $limitedFeatures = null; + private ?bool $ssoAutoRedirect = null; + public function isSsoLogin(): ?bool { return $this->oauthEnabled; @@ -60,4 +62,16 @@ class Instance return $this; } + + public function getSsoAutoRedirect(): ?bool + { + return $this->ssoAutoRedirect; + } + + public function setSsoAutoRedirect(?bool $ssoAutoRedirect): static + { + $this->ssoAutoRedirect = $ssoAutoRedirect; + + return $this; + } }