Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

feat: oidc auto redirect on login page (#649)

Alberto Conte681b01de0e32
diff --git a/.env.example b/.env.example
index 7a7dea17..cc698245 100644
--- a/.env.example
+++ b/.env.example
@@ -30,6 +30,8 @@ CDN_ENDPOINT=/alexandrie/ # The base path in the CDN where files are served from
CONFIG_DISABLE_LANDING=false # Disable the landing page if set to true
CONFIG_DISABLE_SIGNUP=false # Disable the signup page if set to true
CONFIG_DISABLE_NATIVE_LOGIN=false # Disable native username/password login if set to true (useful if you only want OAuth providers)
+CONFIG_HIDE_NATIVE_LOGIN=false # Hide native username/password login if set to true (useful if you only want OAuth providers)
+CONFIG_OIDC_PROVIDER_AUTO_REDIRECT= # Name of OIDC provider to redirect to when landing on login page (can be omitted)
# ==============================================================================
# 3. BACKEND API β€” RUNTIME & SECURITY
diff --git a/docs/.env.example b/docs/.env.example
index fe50fd90..ea07bc5f 100644
--- a/docs/.env.example
+++ b/docs/.env.example
@@ -19,7 +19,9 @@ CDN_ENDPOINT=/alexandrie/ # The base path in the CDN where files are s
CONFIG_DISABLE_LANDING=false # Disable the landing page if set to true
CONFIG_DISABLE_SIGNUP=false # Disable the signup page if set to true
-CONFIG_DISABLE_NATIVE_LOGIN=false # Disable native username/password login if set to true (useful if you only want OAuth providers)
+CONFIG_DISABLE_NATIVE_LOGIN=false # Disable native username/password login if set to true (useful if you only want OAuth providers)
+CONFIG_HIDE_NATIVE_LOGIN=false # Hide native username/password login if set to true (useful if you only want OAuth providers)
+CONFIG_OIDC_PROVIDER_AUTO_REDIRECT= # Name of OIDC provider to redirect to when landing on login page (can be omitted)
# 3. BACKEND API β€” RUNTIME & SECURITY
diff --git a/docs/README.md b/docs/README.md
index 409007c8..d118a7f9 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -74,6 +74,8 @@ These variables define how clients (browsers) reach your services.
CONFIG_DISABLE_LANDING=false
CONFIG_DISABLE_SIGNUP=false
CONFIG_DISABLE_NATIVE_LOGIN=false
+CONFIG_OIDC_PROVIDER_AUTO_REDIRECT=""
+CONFIG_HIDE_NATIVE_LOGIN_FORM=false
```
These variables control specific features of the application (useful for private deployments, internal tools etc.).
@@ -81,6 +83,9 @@ These variables control specific features of the application (useful for private
- `CONFIG_DISABLE_LANDING`: If set to `true`, the landing page is disabled, and users are redirected to the login page. The default is `false`.
- `CONFIG_DISABLE_SIGNUP`: If set to `true`, new user registrations are disabled (in frontend + backend for security). The default is `false`.
- `CONFIG_DISABLE_NATIVE_LOGIN`: If set to `true`, the native username/password login method is disabled. This is useful if you want to enforce OIDC or other external authentication methods. The default is `false`.
+- `CONFIG_HIDE_NATIVE_LOGIN_FORM`: If set to `true`, the native username/password login method is hidden. This is useful if you want to enforce OIDC or other external authentication methods but without setting up `CONFIG_OIDC_PROVIDER_AUTO_REDIRECT`. The default is `false`. Recommended to use in conjunction with `CONFIG_DISABLE_NATIVE_LOGIN`.
+- `CONFIG_OIDC_PROVIDER_AUTO_REDIRECT`: Provide a string that matches the provider name of one of your OIDC providers, if provided the user is automatically redirected to the OIDC login when landing on the login page.
+
### 3. Backend API β€” Runtime & Security
diff --git a/frontend/.env b/frontend/.env
index d54d0b00..64ece16a 100644
--- a/frontend/.env
+++ b/frontend/.env
@@ -2,7 +2,8 @@ NUXT_PUBLIC_BASE_URL=http://localhost:3000
NUXT_PUBLIC_BASE_API=http://localhost:8201
NUXT_PUBLIC_BASE_CDN=http://localhost:9000
-
NUXT_PUBLIC_CONFIG_DISABLE_LANDING_PAGE=false
NUXT_PUBLIC_CONFIG_DISABLE_SIGNUP_PAGE=false
-NUXT_PUBLIC_CONFIG_DISABLE_NATIVE_LOGIN=false
\ No newline at end of file
+NUXT_PUBLIC_CONFIG_DISABLE_NATIVE_LOGIN=false
+NUXT_PUBLIC_CONFIG_HIDE_NATIVE_LOGIN_FORM=false
+#NUXT_PUBLIC_CONFIG_OIDC_PROVIDER_AUTO_REDIRECT=
\ No newline at end of file
diff --git a/frontend/app/components/OIDCProviders.vue b/frontend/app/components/OIDCProviders.vue
index de920545..b9a1592c 100644
--- a/frontend/app/components/OIDCProviders.vue
+++ b/frontend/app/components/OIDCProviders.vue
@@ -25,10 +25,16 @@ import { getProviderConfig } from '~/helpers/oidc-providers';
const { providers, isEnabled, isLoading, fetchProviders, loginWithProvider } = useOIDC();
const { t } = useI18nT();
+const config = useRuntimeConfig();
onMounted(() => {
- fetchProviders();
+ if (!!config.public.configOidcProviderAutoRedirect) {
+ loginWithProvider(config.public.configOidcProviderAutoRedirect)
+ } else {
+ fetchProviders();
+ }
});
+
</script>
<style scoped lang="scss">
diff --git a/frontend/app/pages/(public)/login/index.vue b/frontend/app/pages/(public)/login/index.vue
index 179d79bf..007df21c 100644
--- a/frontend/app/pages/(public)/login/index.vue
+++ b/frontend/app/pages/(public)/login/index.vue
@@ -5,12 +5,12 @@
<template v-if="!step2FA">
<h1>{{ t('public.login.title') }}</h1>
<form @submit.prevent="login">
- <div class="form-group">
+ <div class="form-group" v-if="!hideLoginForm">
<label for="username">{{ t('public.login.form.username') }}</label>
<input id="username" v-model="username" type="username" :class="{ 'is-invalid': errors.username }" :disabled="loginDisabled" />
<p v-if="errors.username" class="invalid-feedback">{{ errors.username }}</p>
</div>
- <div class="form-group">
+ <div class="form-group" v-if="!hideLoginForm">
<label for="password">{{ t('public.login.form.password') }}</label>
<div class="password-input">
<input
@@ -31,7 +31,7 @@
<p v-if="errors.password" class="invalid-feedback">{{ errors.password }}</p>
</div>
<NuxtLinkLocale to="/signup" class="signup-link">{{ t('public.login.needAccount') }}</NuxtLinkLocale>
- <button class="btn" :disabled="loginDisabled">{{ t('public.login.form.submit') }}</button>
+ <button class="btn" :disabled="loginDisabled" v-if="!hideLoginForm">{{ t('public.login.form.submit') }}</button>
<p v-if="loginDisabled" class="disabled">{{ t('public.login.disabled') }}</p>
<OIDCProviders />
@@ -87,6 +87,7 @@ definePageMeta({
const route = useRoute();
const config = useRuntimeConfig();
const loginDisabled = config.public.configDisableNativeLogin;
+const hideLoginForm = config.public.configHideLoginForm;
const errors = ref({ username: '', password: '', general: '' });
const { showPassword, togglePassword } = usePasswordField();
diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts
index 0a7b3157..e5a20294 100644
--- a/frontend/nuxt.config.ts
+++ b/frontend/nuxt.config.ts
@@ -176,8 +176,10 @@ export default defineNuxtConfig({
cdnEndpoint: '/alexandrie/',
configDisableLandingPage: '',
configDisableNativeLogin: false,
+ configHideNativeLogin: false,
// Feature flags
configDisableSignupPage: '',
+ configOidcProviderAutoRedirect: '',
},
},