a27ff49171
terdut can now sign people in through any OIDC provider (written against Authentik), and let groups at the provider decide who may sign in, which teams they belong to and whether they administer the install. Password login keeps working alongside it; TERDUT_PASSWORD_LOGIN=false turns it off, and is refused at startup unless SSO is configured. With no TERDUT_OIDC_* setting nothing changes, so every existing install behaves as before. Identity is (issuer, subject), never email or username: those are mutable at the provider and a recycled address must not inherit an account. An existing user is linked by email only when the provider marks it verified, or TERDUT_OIDC_TRUST_EMAIL is set, which Authentik needs. Group grants are marked source='oidc' on team_members and users, and the sync changes only those rows. Hand-made memberships and administrators are left alone, and the sync bypasses the last-owner and last-admin guards because the provider is the source of truth for what it grants. Editing managed access by hand is refused with 409, since the next sign-in would undo it. The web UI badges it as SSO and disables the controls. Groups are read only at sign-in, so an SSO session carries a hard ceiling (sessions.max_expires_at, 12h by default) that sliding never extends. There is no refresh token, which means API keys of somebody removed at the provider stay valid until an administrator disables the user. That is accepted and documented, not fixed. A client with no browser, the TUI over SSH, signs in with a device code run by terdut itself (POST /api/oidc/device and /device/token), so the terminal never talks to the provider and ends up with the ordinary terdut_session cookie. Only a browser session can approve a code; an API key cannot. /device?code= sends a signed-out visitor through sign-in and back, which is what oidc_logins.next is for. oauth2 is pinned to v0.36.0: v0.37 needs Go 1.26 and the Dockerfile builds on 1.25. Migrations 011 and 012 add tables and defaulted columns only.
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
// State shared between views: who is signed in, the user list, and the open
|
|
// queue that drives the badges.
|
|
|
|
import * as api from './api.js';
|
|
|
|
export const state = {
|
|
me: null, // { user, has_password }
|
|
// How the server can be signed in to. The defaults are an older server's
|
|
// answer: passwords, no single sign-on.
|
|
auth: { password_login: true, oidc: { enabled: false, name: '' } },
|
|
open: [], // the default queue: open, not snoozed
|
|
teams: [], // the teams the viewer belongs to, each with their role
|
|
};
|
|
|
|
// The team whose schedule and settings the views act on. A viewer in one team —
|
|
// which is everybody until somebody makes a second — never has to choose.
|
|
export function currentTeam() {
|
|
return state.teams[0] || null;
|
|
}
|
|
|
|
export function myID() {
|
|
return state.me ? state.me.user.id : null;
|
|
}
|
|
|
|
// The user list changes rarely; it is fetched once and then at most every
|
|
// five minutes, for the assign sheet and for display names.
|
|
let usersCache = null;
|
|
let usersAt = 0;
|
|
export async function users() {
|
|
if (!usersCache || Date.now() - usersAt > 5 * 60 * 1000) {
|
|
usersCache = await api.users();
|
|
usersAt = Date.now();
|
|
}
|
|
return usersCache;
|
|
}
|
|
|
|
export async function loadTeams() {
|
|
state.teams = await api.teams();
|
|
return state.teams;
|
|
}
|
|
|
|
export function reset() {
|
|
state.me = null;
|
|
state.open = [];
|
|
state.teams = [];
|
|
usersCache = null;
|
|
}
|