mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
feat(auth): let admins keep the login page on OIDC-only instances (#2925)
A new app setting oidc_auto_redirect (default on) is part of the admin form and the public app config. Off, an instance without password login no longer sends visitors straight to the IdP: the login page shows its SSO button, also while the cached config is read. Admin toggle on desktop and phone.
This commit is contained in:
@@ -33,7 +33,7 @@ export default function MAdminSettingsSection({ admin, t }: MAdminSettingsSectio
|
||||
placesGoogleOnly, handleTogglePlacesGoogleOnly,
|
||||
placeShadowEnabled,
|
||||
passwordLogin, setPasswordLogin, passwordRegistration, setPasswordRegistration,
|
||||
oidcLogin, setOidcLogin, oidcRegistration, setOidcRegistration,
|
||||
oidcLogin, setOidcLogin, oidcRegistration, setOidcRegistration, oidcAutoRedirect, setOidcAutoRedirect,
|
||||
envOverrideOidcOnly, oidcConfigured, requireMfa,
|
||||
passkeyLogin, setPasskeyLogin, passkeyConfigured,
|
||||
webauthnRpId, setWebauthnRpId, webauthnOrigins, setWebauthnOrigins, savingWebauthn, handleSaveWebauthn,
|
||||
@@ -112,6 +112,19 @@ export default function MAdminSettingsSection({ admin, t }: MAdminSettingsSectio
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{oidcConfigured && (
|
||||
<MAdminRow
|
||||
title={t('admin.oidcAutoRedirect')}
|
||||
hint={t('admin.oidcAutoRedirectHint')}
|
||||
trailing={
|
||||
<MToggle
|
||||
checked={oidcAutoRedirect}
|
||||
ariaLabel={t('admin.oidcAutoRedirect')}
|
||||
onChange={(v) => handleToggleAuthSetting('oidc_auto_redirect', v, setOidcAutoRedirect)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</MAdminCard>
|
||||
|
||||
{/* Passkey login */}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// FE-ADMSET-001 to FE-ADMSET-043
|
||||
// FE-ADMSET-001 to FE-ADMSET-044
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import React from 'react';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -143,6 +143,7 @@ describe('AdminSettingsTab', () => {
|
||||
|
||||
expect(screen.queryByText('SSO Login')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('SSO Auto-Provisioning')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('Go straight to SSO')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-ADMSET-008: SSO login toggle sends the inverted value', () => {
|
||||
@@ -167,6 +168,14 @@ describe('AdminSettingsTab', () => {
|
||||
expect(admin.handleToggleAuthSetting).toHaveBeenCalledWith('oidc_registration', true, admin.setOidcRegistration);
|
||||
});
|
||||
|
||||
it('FE-ADMSET-044: the SSO auto redirect toggle sends the inverted value (#2925)', () => {
|
||||
const admin = renderTab({ oidcConfigured: true, oidcAutoRedirect: true });
|
||||
|
||||
fireEvent.click(toggleFor('Go straight to SSO'));
|
||||
|
||||
expect(admin.handleToggleAuthSetting).toHaveBeenCalledWith('oidc_auto_redirect', false, admin.setOidcAutoRedirect);
|
||||
});
|
||||
|
||||
it('FE-ADMSET-011: passkey toggle sends the inverted value', () => {
|
||||
const admin = renderTab({ passkeyLogin: false });
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ export default function AdminSettingsTab({ admin, t }: AdminSettingsTabProps): R
|
||||
placeShadowEnabled,
|
||||
oidcConfig, setOidcConfig, savingOidc,
|
||||
passwordLogin, setPasswordLogin, passwordRegistration, setPasswordRegistration,
|
||||
oidcLogin, setOidcLogin, oidcRegistration, setOidcRegistration,
|
||||
oidcLogin, setOidcLogin, oidcRegistration, setOidcRegistration, oidcAutoRedirect, setOidcAutoRedirect,
|
||||
envOverrideOidcOnly, oidcConfigured, requireMfa,
|
||||
passkeyLogin, setPasskeyLogin, passkeyConfigured,
|
||||
webauthnRpId, setWebauthnRpId, webauthnOrigins, setWebauthnOrigins, savingWebauthn, handleSaveWebauthn,
|
||||
@@ -235,6 +235,20 @@ export default function AdminSettingsTab({ admin, t }: AdminSettingsTabProps): R
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{/* Whether an instance without password login skips its own login page (#2925) */}
|
||||
{oidcConfigured && (
|
||||
<SettingRow
|
||||
label={t('admin.oidcAutoRedirect')}
|
||||
hint={t('admin.oidcAutoRedirectHint')}
|
||||
control={
|
||||
<ToggleSwitch
|
||||
on={oidcAutoRedirect}
|
||||
label={t('admin.oidcAutoRedirect')}
|
||||
onToggle={() => handleToggleAuthSetting('oidc_auto_redirect', !oidcAutoRedirect, setOidcAutoRedirect)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</SettingRows>
|
||||
</SettingsCard>
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ describe('useAdmin', () => {
|
||||
password_registration: false,
|
||||
oidc_login: false,
|
||||
oidc_registration: false,
|
||||
oidc_auto_redirect: false,
|
||||
env_override_oidc_only: true,
|
||||
oidc_configured: true,
|
||||
require_mfa: 1,
|
||||
@@ -116,6 +117,7 @@ describe('useAdmin', () => {
|
||||
expect(result.current.passwordRegistration).toBe(false);
|
||||
expect(result.current.oidcLogin).toBe(false);
|
||||
expect(result.current.oidcRegistration).toBe(false);
|
||||
expect(result.current.oidcAutoRedirect).toBe(false);
|
||||
expect(result.current.envOverrideOidcOnly).toBe(true);
|
||||
expect(result.current.oidcConfigured).toBe(true);
|
||||
expect(result.current.requireMfa).toBe(true);
|
||||
|
||||
@@ -145,6 +145,7 @@ export function useAdmin() {
|
||||
const [passwordRegistration, setPasswordRegistration] = useState<boolean>(true)
|
||||
const [oidcLogin, setOidcLogin] = useState<boolean>(true)
|
||||
const [oidcRegistration, setOidcRegistration] = useState<boolean>(true)
|
||||
const [oidcAutoRedirect, setOidcAutoRedirect] = useState<boolean>(true)
|
||||
const [envOverrideOidcOnly, setEnvOverrideOidcOnly] = useState<boolean>(false)
|
||||
const [oidcConfigured, setOidcConfigured] = useState<boolean>(false)
|
||||
const [requireMfa, setRequireMfa] = useState<boolean>(false)
|
||||
@@ -286,6 +287,7 @@ export function useAdmin() {
|
||||
setPasswordRegistration(config.password_registration ?? config.allow_registration ?? true)
|
||||
setOidcLogin(config.oidc_login ?? true)
|
||||
setOidcRegistration(config.oidc_registration ?? config.allow_registration ?? true)
|
||||
setOidcAutoRedirect(config.oidc_auto_redirect ?? true)
|
||||
setEnvOverrideOidcOnly(config.env_override_oidc_only ?? false)
|
||||
setOidcConfigured(config.oidc_configured ?? false)
|
||||
if (config.require_mfa !== undefined) setRequireMfa(!!config.require_mfa)
|
||||
@@ -600,7 +602,7 @@ export function useAdmin() {
|
||||
collabFeatures, setCollabFeatures,
|
||||
oidcConfig, setOidcConfig, savingOidc, setSavingOidc,
|
||||
passwordLogin, setPasswordLogin, passwordRegistration, setPasswordRegistration,
|
||||
oidcLogin, setOidcLogin, oidcRegistration, setOidcRegistration,
|
||||
oidcLogin, setOidcLogin, oidcRegistration, setOidcRegistration, oidcAutoRedirect, setOidcAutoRedirect,
|
||||
envOverrideOidcOnly, setEnvOverrideOidcOnly, oidcConfigured, setOidcConfigured,
|
||||
requireMfa, setRequireMfa,
|
||||
passkeyLogin, setPasskeyLogin, passkeyConfigured,
|
||||
|
||||
@@ -1212,6 +1212,43 @@ describe('useLogin — the wait before the sign-in is known (#1167)', () => {
|
||||
expect(window.location.href).toBe('http://localhost/login');
|
||||
});
|
||||
|
||||
it('FE-LOGIN-HOOK-215: with the auto redirect turned off the page stays, with its SSO button (#2925)', async () => {
|
||||
server.use(
|
||||
http.get('/api/auth/app-config', () => HttpResponse.json({ ...oidcOnlyConfig(), oidc_auto_redirect: false })),
|
||||
);
|
||||
const { result } = renderLogin();
|
||||
await ready(result);
|
||||
|
||||
expect(result.current.oidcOnly).toBe(true);
|
||||
expect(result.current.redirectScreen).toBe(false);
|
||||
expect(result.current.configWait).toBe(false);
|
||||
expect(window.location.href).toBe('http://localhost/login');
|
||||
});
|
||||
|
||||
it('FE-LOGIN-HOOK-216: a cached config with the auto redirect off announces no redirect while the probe is out', async () => {
|
||||
const config = { ...oidcOnlyConfig(), oidc_auto_redirect: false };
|
||||
localStorage.setItem(CONFIG_CACHE_KEY, JSON.stringify(config));
|
||||
const release = heldConfig(config);
|
||||
const { result } = renderLogin();
|
||||
|
||||
expect(result.current.redirectScreen).toBe(false);
|
||||
expect(result.current.configWait).toBe(true);
|
||||
|
||||
release();
|
||||
await ready(result);
|
||||
expect(result.current.redirectScreen).toBe(false);
|
||||
expect(window.location.href).toBe('http://localhost/login');
|
||||
});
|
||||
|
||||
it('FE-LOGIN-HOOK-217: a server from before the switch, with no field, keeps the redirect', async () => {
|
||||
const config: Record<string, unknown> = { ...oidcOnlyConfig() };
|
||||
delete config.oidc_auto_redirect;
|
||||
server.use(http.get('/api/auth/app-config', () => HttpResponse.json(config)));
|
||||
renderLogin();
|
||||
|
||||
await waitFor(() => expect(window.location.href).toBe('/api/auth/oidc/login?remember=1'));
|
||||
});
|
||||
|
||||
it('FE-LOGIN-HOOK-210: right after a sign-out the cached redirect is not announced', async () => {
|
||||
localStorage.setItem(CONFIG_CACHE_KEY, JSON.stringify(oidcOnlyConfig()));
|
||||
const release = heldConfig(oidcOnlyConfig());
|
||||
|
||||
@@ -33,6 +33,8 @@ interface AppConfig {
|
||||
password_registration: boolean
|
||||
oidc_login: boolean
|
||||
oidc_registration: boolean
|
||||
/** False when the admin wants the login page shown before the IdP; absent on servers from before #2925. */
|
||||
oidc_auto_redirect?: boolean
|
||||
passkey_login?: boolean
|
||||
passkey_configured?: boolean
|
||||
env_override_oidc_only: boolean
|
||||
@@ -56,6 +58,14 @@ function readCachedConfig(): AppConfig | null {
|
||||
const isOidcOnly = (config: AppConfig | null): boolean =>
|
||||
!!config && !config.password_login && config.oidc_login && config.oidc_configured
|
||||
|
||||
/**
|
||||
* Whether the login page leaves for the IdP by itself: an OIDC-only instance
|
||||
* does, unless its admin turned that off to show the page and its SSO button
|
||||
* first (#2925). A config without the field keeps the redirect.
|
||||
*/
|
||||
const redirectsToIdp = (config: AppConfig | null): boolean =>
|
||||
isOidcOnly(config) && config?.oidc_auto_redirect !== false
|
||||
|
||||
/**
|
||||
* Login data hook — owns the whole auth surface: login/register/demo, the MFA
|
||||
* step-up, the must-change-password step, the OIDC code exchange + error
|
||||
@@ -88,7 +98,7 @@ export function useLogin() {
|
||||
const [cachedConfig] = useState(readCachedConfig)
|
||||
const [expectRedirect] = useState(() => {
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
return !isNativeApp() && isOidcOnly(cachedConfig) && !!cachedConfig?.has_users
|
||||
return !isNativeApp() && redirectsToIdp(cachedConfig) && !!cachedConfig?.has_users
|
||||
&& !params.get('invite') && !params.get('oidc_code') && !params.get('oidc_error')
|
||||
})
|
||||
const [idpRedirect, setIdpRedirect] = useState(false)
|
||||
@@ -198,7 +208,7 @@ export function useLogin() {
|
||||
// and auto-redirecting to the IdP could loop if the proxy changed.
|
||||
// Not in the app: its WebView cannot host the IdP, and opening the
|
||||
// system browser uninvited on every launch would be worse than a button.
|
||||
if (allowRedirect && !fromCache && !nativeApp && isOidcOnly(config) && config.has_users && !invite && !noRedirect) {
|
||||
if (allowRedirect && !fromCache && !nativeApp && redirectsToIdp(config) && config.has_users && !invite && !noRedirect) {
|
||||
setIdpRedirect(true)
|
||||
window.location.href = IDP_LOGIN_URL
|
||||
}
|
||||
|
||||
@@ -449,6 +449,8 @@ export interface AppConfig {
|
||||
password_registration?: boolean
|
||||
oidc_login?: boolean
|
||||
oidc_registration?: boolean
|
||||
/** Whether an instance without password login sends visitors straight to the IdP */
|
||||
oidc_auto_redirect?: boolean
|
||||
env_override_oidc_only?: boolean
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user