mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +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:
@@ -359,6 +359,9 @@ export class AuthService {
|
||||
password_registration: isDemo ? false : toggles.password_registration,
|
||||
oidc_login: toggles.oidc_login,
|
||||
oidc_registration: isDemo ? false : toggles.oidc_registration,
|
||||
// Read by the login page only where password login is off: anything but
|
||||
// 'false' keeps the redirect every such instance had before (#2925).
|
||||
oidc_auto_redirect: settings.get('oidc_auto_redirect') !== 'false',
|
||||
// Passkey login: the instance toggle + whether a usable RP ID resolves for
|
||||
// this deployment. The login page shows the passkey button only when both
|
||||
// are true. `passkey_configured` stays a pure boolean — it never leaks the
|
||||
|
||||
@@ -84,6 +84,9 @@ export const APP_SETTINGS = {
|
||||
password_registration: { schema: flag, default: 'true', adminForm: true },
|
||||
oidc_login: { schema: flag, default: 'true', adminForm: true, managedLocked: true },
|
||||
oidc_registration: { schema: flag, default: 'true', adminForm: true, managedLocked: true },
|
||||
// Whether an instance without password login sends a visitor straight to the
|
||||
// identity provider. Off shows the login page with its SSO button first (#2925).
|
||||
oidc_auto_redirect: { schema: flag, default: 'true', adminForm: true, publicConfig: true },
|
||||
passkey_login: { schema: flag, default: 'false', adminForm: true },
|
||||
webauthn_rp_id: { schema: text, default: null, adminForm: true, managedLocked: true },
|
||||
webauthn_origins: { schema: text, default: null, adminForm: true, managedLocked: true },
|
||||
|
||||
@@ -120,6 +120,28 @@ describe('Auth e2e (real auth guard + real service + real cookie service + temp
|
||||
expect(res.body.permissions).toBeUndefined();
|
||||
});
|
||||
|
||||
it('PUT /app-settings oidc_auto_redirect reaches the public app-config the login page reads (#2925)', async () => {
|
||||
const admin = createUser(db as never, {
|
||||
username: 'redirect-admin',
|
||||
email: 'redirect-admin@example.test',
|
||||
role: 'admin',
|
||||
});
|
||||
const autoRedirect = async () => (await request(server).get('/api/auth/app-config')).body.oidc_auto_redirect;
|
||||
try {
|
||||
expect(await autoRedirect()).toBe(true);
|
||||
|
||||
const res = await request(server)
|
||||
.put('/api/auth/app-settings')
|
||||
.set('Cookie', sessionCookie(admin.user.id))
|
||||
.send({ oidc_auto_redirect: false });
|
||||
expect(res.status).toBe(200);
|
||||
expect(await readAppSetting(orm, 'oidc_auto_redirect')).toBe('false');
|
||||
expect(await autoRedirect()).toBe(false);
|
||||
} finally {
|
||||
await deleteRows(orm, AppSettings, { key: 'oidc_auto_redirect' });
|
||||
}
|
||||
});
|
||||
|
||||
it('GET /me requires a session (401 without a cookie)', async () => {
|
||||
expect((await request(server).get('/api/auth/me')).status).toBe(401);
|
||||
});
|
||||
|
||||
@@ -45,6 +45,7 @@ describe('the derived key lists', () => {
|
||||
'password_registration',
|
||||
'oidc_login',
|
||||
'oidc_registration',
|
||||
'oidc_auto_redirect',
|
||||
'passkey_login',
|
||||
'webauthn_rp_id',
|
||||
'webauthn_origins',
|
||||
@@ -82,6 +83,7 @@ describe('the derived key lists', () => {
|
||||
'places_details_enabled',
|
||||
'places_enrich_enabled',
|
||||
'place_shadow_enabled',
|
||||
'oidc_auto_redirect',
|
||||
].sort(),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -815,6 +815,15 @@ describe('getAppConfig', () => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it('AUTH-DB-052d: oidc_auto_redirect stays on until an admin stores false (#2925)', async () => {
|
||||
createUser(testDb);
|
||||
expect((await svc.getAppConfig(null)).oidc_auto_redirect).toBe(true);
|
||||
await appSetting('oidc_auto_redirect', 'false');
|
||||
expect((await svc.getAppConfig(null)).oidc_auto_redirect).toBe(false);
|
||||
await appSetting('oidc_auto_redirect', 'true');
|
||||
expect((await svc.getAppConfig(null)).oidc_auto_redirect).toBe(true);
|
||||
});
|
||||
|
||||
it('AUTH-DB-052b: managed is false unless the install says otherwise', async () => {
|
||||
createUser(testDb);
|
||||
expect((await svc.getAppConfig(null)).managed).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user