List, switch off/on and delete Authentik users

Apps → Authentik gets a Users section for administrators: a searchable list
of people (service accounts left out) with status, administrator and last
sign-in, and Switch off / Switch on / Delete. Switching off sends only
is_active; deleting needs the user name typed and re-checked by the server.
The server refuses service accounts, the account the token belongs to and
the last active administrator. Each action is audited. The token field is
now "Token for making and managing users".

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-01 00:31:14 +01:00
1 parent aa95d6b314
commit 0cd11268ee
12 files changed
+733 -21

No files matched your search

+15
View File
@@ -1771,6 +1771,18 @@ export interface AuthentikNewUser {
groups: string[];
}
/** A person in Authentik, as the list that looks after them shows them. */
export interface AuthentikPerson {
pk: number;
username: string;
name: string;
email: string | null;
active: boolean;
/** May do everything in Authentik. */
admin: boolean;
lastLogin: string | null;
}
/** A user Authentik made, and the one-time link for them to choose a password with (null, with the reason, when that could not be made). */
export interface AuthentikUserMade {
user: { pk: number; username: string; name: string };
@@ -3412,6 +3424,9 @@ export const api = {
list: () => request<{ authentiks: AuthentikInfo[] }>("/api/authentik"),
groups: (id: number) => request<{ groups: AuthentikGroup[] }>(`/api/authentik/${id}/groups`),
createUser: (id: number, body: AuthentikNewUser) => request<AuthentikUserMade>(`/api/authentik/${id}/users`, { method: "POST", body: JSON.stringify(body) }),
users: (id: number, search = "") => request<{ users: AuthentikPerson[]; more: boolean; self: number | null }>(`/api/authentik/${id}/users${search.trim() ? `?search=${encodeURIComponent(search.trim())}` : ""}`),
setUserActive: (id: number, pk: number, active: boolean) => request<{ user: AuthentikPerson }>(`/api/authentik/${id}/users/${pk}/active`, { method: "POST", body: JSON.stringify({ active }) }),
deleteUser: (id: number, pk: number, username: string) => request<void>(`/api/authentik/${id}/users/${pk}`, { method: "DELETE", body: JSON.stringify({ username }) }),
removeWriteToken: (id: number) => request<void>(`/api/authentik/${id}/write-token`, { method: "DELETE" }),
},
jellyfin: {
+2 -2
View File
@@ -25,7 +25,7 @@ export default function AuthentikNewUser({ a, onChanged }: { a: AuthentikInfo; o
if (!a.canCreateUsers) {
return (
<div className="text-secondary small mt-3">
To make users from here, give this Authentik a token that may add users: <Link to="/integrations">Integrations</Link> → edit → <em>Token for making users</em>.
To make and manage users from here, give this Authentik a token that may add, change and delete them: <Link to="/integrations">Integrations</Link> → edit → <em>Token for making and managing users</em>.
</div>
);
}
@@ -68,7 +68,7 @@ export default function AuthentikNewUser({ a, onChanged }: { a: AuthentikInfo; o
}
async function stopAllowing() {
if (!(await confirmDialog({ title: "Stop making users", message: `Remove the token for making users from "${a.name}"? Reading it carries on. You can add one again under Integrations.`, confirmLabel: "Remove", danger: true }))) return;
if (!(await confirmDialog({ title: "Stop managing users", message: `Remove the token for making and managing users from "${a.name}"? Reading it carries on. You can add one again under Integrations.`, confirmLabel: "Remove", danger: true }))) return;
try {
await api.authentik.removeWriteToken(a.id);
close();
+159
View File
@@ -0,0 +1,159 @@
import { useState, type FormEvent } from "react";
import { api, type AuthentikInfo, type AuthentikPerson } from "../api/client";
import TimeAgo from "./TimeAgo";
import { ErrorNotice } from "./Notice";
import { confirmDialog, promptDialog } from "../utils/dialogs";
import { readableError } from "../utils/errors";
/**
* The people in an Authentik, for an administrator to switch off, switch on again or delete. Switching off is the way that can be undone; deleting asks for the user name to be typed.
* The account the token belongs to has no buttons, and neither does the last active administrator: the server refuses them too, and says why.
*/
export default function AuthentikUserList({ a }: { a: AuthentikInfo }) {
const [people, setPeople] = useState<AuthentikPerson[] | null>(null);
const [more, setMore] = useState(false);
const [self, setSelf] = useState<number | null>(null);
const [search, setSearch] = useState("");
const [busy, setBusy] = useState<number | "list" | null>(null);
const [error, setError] = useState<string | null>(null);
if (!a.canCreateUsers) return null;
async function load(q = search) {
setBusy("list");
setError(null);
try {
const r = await api.authentik.users(a.id, q);
setPeople(r.users);
setMore(r.more);
setSelf(r.self);
} catch (err) {
setError(readableError(err));
} finally {
setBusy(null);
}
}
function find(e: FormEvent) {
e.preventDefault();
void load();
}
async function switchTo(p: AuthentikPerson, on: boolean) {
if (!on) {
const ok = await confirmDialog({
title: "Switch off user",
message: `Switch off "${p.username}" in ${a.name}? They can no longer sign in to anything behind Authentik. Nothing of theirs is lost, and switching on again brings it all back. A session they already have in this app is not ended by this — end it under Users → Signed in now.`,
confirmLabel: "Switch off",
danger: true,
});
if (!ok) return;
}
setBusy(p.pk);
setError(null);
try {
await api.authentik.setUserActive(a.id, p.pk, on);
await load();
} catch (err) {
setError(readableError(err));
setBusy(null);
}
}
async function remove(p: AuthentikPerson) {
const typed = await promptDialog({
title: "Delete user",
message: `This deletes "${p.username}" in ${a.name} for good, with their account there. It cannot be undone — switching them off is the way back. Type the user name to confirm.`,
label: "User name",
confirmLabel: "Delete",
required: true,
});
if (typed === null) return;
if (typed.trim() !== p.username) {
setError("That is not the user name, so nothing was deleted.");
return;
}
setBusy(p.pk);
setError(null);
try {
await api.authentik.deleteUser(a.id, p.pk, p.username);
await load();
} catch (err) {
setError(readableError(err));
setBusy(null);
}
}
return (
<div className="mt-3">
<h4>Users</h4>
<ErrorNotice error={error} />
{people === null ? (
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => void load()} disabled={busy !== null}>
{busy === "list" ? "Reading…" : "Show users"}
</button>
) : (
<>
<form onSubmit={find} className="input-group input-group-sm mb-2" style={{ maxWidth: 360 }}>
<input className="form-control" placeholder="Search by name or email" aria-label="Search users" maxLength={100} value={search} onChange={(e) => setSearch(e.target.value)} />
<button type="submit" className="btn btn-outline-secondary" disabled={busy !== null}>
Search
</button>
</form>
{people.length === 0 ? (
<div className="text-secondary mb-2">No users{search.trim() ? " match that" : ""}.</div>
) : (
<div className="table-responsive">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>User</th>
<th>Status</th>
<th>Last sign-in</th>
<th className="text-end">&nbsp;</th>
</tr>
</thead>
<tbody>
{people.map((p) => (
<tr key={p.pk} className={p.active ? "" : "text-secondary"}>
<td>
{p.username}
{p.name !== p.username && <span className="text-secondary"> — {p.name}</span>}
{p.email && <div className="small text-secondary">{p.email}</div>}
</td>
<td>
{p.active ? <span className="badge bg-green-lt text-green">On</span> : <span className="badge bg-secondary-lt text-secondary">Off</span>}
{p.admin && <span className="badge bg-yellow-lt text-yellow ms-1">administrator</span>}
</td>
<td className="text-secondary">{p.lastLogin ? <TimeAgo value={p.lastLogin} /> : "never"}</td>
<td className="text-end text-nowrap">
{p.pk === self ? (
<span className="small text-secondary" title="The account the token for managing users belongs to; it is looked after in Authentik.">
this token&rsquo;s account
</span>
) : (
<>
<button type="button" className="btn btn-sm btn-outline-secondary me-1" disabled={busy !== null} onClick={() => void switchTo(p, !p.active)}>
{p.active ? "Switch off" : "Switch on"}
</button>
<button type="button" className="btn btn-sm btn-outline-danger" disabled={busy !== null} onClick={() => void remove(p)}>
Delete
</button>
</>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
{more && <div className="text-secondary small mb-2">Only the first 200 are shown — search to find the others.</div>}
<button type="button" className="btn btn-sm btn-link text-secondary px-0" onClick={() => setPeople(null)}>
Hide users
</button>
</>
)}
</div>
);
}
+3 -1
View File
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { api, type AuthentikInfo, type CurrentUser } from "../api/client";
import AuthentikNewUser from "../components/AuthentikNewUser";
import AuthentikUserList from "../components/AuthentikUserList";
import EmptyState from "../components/EmptyState";
import TimeAgo from "../components/TimeAgo";
import { BlockSkeleton } from "../components/Skeleton";
@@ -128,6 +129,7 @@ function Card({ a, isAdmin, onChanged }: { a: AuthentikInfo; isAdmin: boolean; o
</>
)}
{isAdmin && a.enabled && <AuthentikNewUser a={a} onChanged={onChanged} />}
{isAdmin && a.enabled && <AuthentikUserList a={a} />}
</div>
</div>
);
@@ -158,7 +160,7 @@ export default function Authentik({ user }: { user: CurrentUser }) {
<h2 className="page-title">Authentik</h2>
<p className="text-secondary">
The sign-in in front of everything else. It is read every few minutes with an API token (see <Link to="/integrations">Integrations</Link>). An <strong>outpost that goes quiet</strong> (the apps it guards stop letting anyone in), a <strong>certificate</strong> or an{" "}
<strong>API token</strong> that is about to run out, <strong>no worker</strong> and a burst of <strong>failed sign-ins</strong> are alerts — see <Link to="/alerts">Alerts</Link>.{user.role === "admin" && " An administrator can also make a user here, with a one-time link for them to choose a password."}
<strong>API token</strong> that is about to run out, <strong>no worker</strong> and a burst of <strong>failed sign-ins</strong> are alerts — see <Link to="/alerts">Alerts</Link>.{user.role === "admin" && " An administrator can also make a user here, with a one-time link for them to choose a password, and switch users off or delete them."}
</p>
<ErrorNotice error={error} />
{!data && !error && <BlockSkeleton lines={4} />}