feat: auto redirect to the SSO login page

This commit is contained in:
Maël Gangloff 2025-12-07 14:32:48 +01:00
parent dd6c121936
commit dd5dba17fc
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
9 changed files with 29 additions and 3 deletions

1
.env
View File

@ -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

View File

@ -129,7 +129,7 @@ export default function App(): React.ReactElement {
}}
>
<Routes>
<Route path='/' element={<Navigate to='/login'/>}/>
<Route path='/' element={<Navigate to='/home'/>}/>
<Route path='/home' element={<TextPage resource='home.md'/>}/>
<Route path='/search/domain' element={<DomainSearchPage/>}/>

View File

@ -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 = [

View File

@ -105,6 +105,7 @@ export interface Watchlist {
}
export interface InstanceConfig {
ssoAutoRedirect: boolean
ssoLogin: boolean
limtedFeatures: boolean
registerEnabled: boolean

View File

@ -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)%'

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}
}