Make Authentik users from Apps → Authentik, with a one-time recovery link
An administrator can make a user (user name, name, optional email, groups) and gets a recovery link to send them, so they choose their own password; no password is set or seen here. Uses a separate optional "Token for making users" on the Authentik integration; reading never uses it, and it can be removed again from the page. The link is shown once and never stored or audited; the audit log records who made which user and link. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ca83994fb
commit
aa95d6b314
13 files changed
+892
-18
No files matched your search
+1
-1
@@ -175,7 +175,7 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/home-assistant" element={<HomeAssistant user={user} />} />
|
||||
<Route path="/ups" element={<Ups user={user} />} />
|
||||
<Route path="/jellyfin" element={<Jellyfin />} />
|
||||
<Route path="/authentik" element={<Authentik />} />
|
||||
<Route path="/authentik" element={<Authentik user={user} />} />
|
||||
<Route path="/prometheus" element={<Prometheus />} />
|
||||
<Route path="/immich" element={<Immich />} />
|
||||
<Route path="/paperless" element={<Paperless />} />
|
||||
|
||||
@@ -1737,6 +1737,8 @@ export interface AuthentikInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
/** Whether it was given a token to make users with. */
|
||||
canCreateUsers: boolean;
|
||||
status: { at: string; ok: boolean; error: string | null } | null;
|
||||
fresh: boolean;
|
||||
state: {
|
||||
@@ -1755,6 +1757,27 @@ export interface AuthentikInfo {
|
||||
problems: { key: string; message: string; severity: "warning" | "critical" }[];
|
||||
}
|
||||
|
||||
/** A group in Authentik a new user can be put in; `admin` ones make the user an administrator there. */
|
||||
export interface AuthentikGroup {
|
||||
id: string;
|
||||
name: string;
|
||||
admin: boolean;
|
||||
}
|
||||
|
||||
export interface AuthentikNewUser {
|
||||
username: string;
|
||||
name: string;
|
||||
email: string;
|
||||
groups: string[];
|
||||
}
|
||||
|
||||
/** 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 };
|
||||
link: string | null;
|
||||
linkError: string | null;
|
||||
}
|
||||
|
||||
export interface JellyfinHistory {
|
||||
jellyfin: { id: number; name: string };
|
||||
days: number;
|
||||
@@ -3387,6 +3410,9 @@ export const api = {
|
||||
},
|
||||
authentik: {
|
||||
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) }),
|
||||
removeWriteToken: (id: number) => request<void>(`/api/authentik/${id}/write-token`, { method: "DELETE" }),
|
||||
},
|
||||
jellyfin: {
|
||||
list: () => request<{ jellyfins: JellyfinInfo[] }>("/api/jellyfin"),
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type AuthentikGroup, type AuthentikInfo, type AuthentikUserMade } from "../api/client";
|
||||
import CopyButton from "./CopyButton";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
const EMPTY = { username: "", name: "", email: "" };
|
||||
|
||||
/**
|
||||
* Making a user in Authentik, for an administrator: a name, an email if there is one, the groups, and out comes a one-time link for them to choose their own password with. The app never
|
||||
* sees or sets a password, and the link is shown here once — it is not kept anywhere.
|
||||
*/
|
||||
export default function AuthentikNewUser({ a, onChanged }: { a: AuthentikInfo; onChanged: () => void }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [fields, setFields] = useState(EMPTY);
|
||||
const [groups, setGroups] = useState<AuthentikGroup[] | null>(null);
|
||||
const [groupsError, setGroupsError] = useState<string | null>(null);
|
||||
const [picked, setPicked] = useState<string[]>([]);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [made, setMade] = useState<AuthentikUserMade | null>(null);
|
||||
|
||||
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>.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
async function show() {
|
||||
setOpen(true);
|
||||
setMade(null);
|
||||
setError(null);
|
||||
setGroupsError(null);
|
||||
try {
|
||||
setGroups((await api.authentik.groups(a.id)).groups);
|
||||
} catch (err) {
|
||||
setGroups([]);
|
||||
setGroupsError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
setOpen(false);
|
||||
setFields(EMPTY);
|
||||
setPicked([]);
|
||||
setMade(null);
|
||||
setError(null);
|
||||
}
|
||||
|
||||
async function submit(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
if (busy) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
setMade(await api.authentik.createUser(a.id, { ...fields, groups: picked }));
|
||||
setFields(EMPTY);
|
||||
setPicked([]);
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
try {
|
||||
await api.authentik.removeWriteToken(a.id);
|
||||
close();
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
const toggle = (id: string) => setPicked((p) => (p.includes(id) ? p.filter((x) => x !== id) : [...p, id]));
|
||||
|
||||
return (
|
||||
<div className="mt-3">
|
||||
<h4>New user</h4>
|
||||
{!open && (
|
||||
<div className="d-flex flex-wrap align-items-center gap-2">
|
||||
<button type="button" className="btn btn-sm btn-primary" onClick={() => void show()}>
|
||||
New user…
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-link text-secondary" onClick={() => void stopAllowing()}>
|
||||
Stop allowing this
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{open && made && (
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className="mb-2">
|
||||
<strong>{made.user.username}</strong> was made in {a.name}.
|
||||
</div>
|
||||
{made.link ? (
|
||||
<>
|
||||
<div className="input-group mb-2">
|
||||
<input className="form-control" readOnly value={made.link} aria-label="Recovery link" onFocus={(e) => e.currentTarget.select()} />
|
||||
<CopyButton text={made.link} />
|
||||
</div>
|
||||
<div className="text-secondary small mb-3">
|
||||
Send them this link. They open it and choose their own password; it works once. It is shown here only and kept nowhere, so copy it now. It points at the address this app reaches Authentik at, so the Authentik address in Integrations should be
|
||||
the one people use.
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="alert alert-warning mb-3">
|
||||
The user exists, but no link could be made: {made.linkError ?? "no answer"}. Make one in Authentik: Directory → Users → {made.user.username} → Create recovery link.
|
||||
</div>
|
||||
)}
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary me-2" onClick={() => void show()}>
|
||||
Make another
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-link text-secondary" onClick={close}>
|
||||
Done
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{open && !made && (
|
||||
<form onSubmit={submit} className="card card-sm">
|
||||
<div className="card-body">
|
||||
<ErrorNotice error={error} />
|
||||
<div className="row g-2 mb-3">
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor={`ak-user-${a.id}`}>
|
||||
User name
|
||||
</label>
|
||||
<input id={`ak-user-${a.id}`} className="form-control" required maxLength={150} autoComplete="off" value={fields.username} onChange={(e) => setFields({ ...fields, username: e.target.value })} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor={`ak-name-${a.id}`}>
|
||||
Name
|
||||
</label>
|
||||
<input id={`ak-name-${a.id}`} className="form-control" required maxLength={200} autoComplete="off" value={fields.name} onChange={(e) => setFields({ ...fields, name: e.target.value })} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor={`ak-email-${a.id}`}>
|
||||
Email <span className="text-secondary">(optional)</span>
|
||||
</label>
|
||||
<input id={`ak-email-${a.id}`} type="email" className="form-control" maxLength={254} autoComplete="off" value={fields.email} onChange={(e) => setFields({ ...fields, email: e.target.value })} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-label">Groups</div>
|
||||
{groups === null && <div className="text-secondary small mb-3">Reading the groups…</div>}
|
||||
{groupsError && <div className="text-yellow small mb-2">The groups could not be read: {groupsError}. The user can still be made, without groups.</div>}
|
||||
{groups && groups.length === 0 && !groupsError && <div className="text-secondary small mb-3">There are no groups.</div>}
|
||||
{groups && groups.length > 0 && (
|
||||
<div className="mb-3">
|
||||
{groups.map((g) => (
|
||||
<label key={g.id} className="form-check">
|
||||
<input type="checkbox" className="form-check-input" checked={picked.includes(g.id)} onChange={() => toggle(g.id)} />
|
||||
<span className="form-check-label">
|
||||
{g.name}
|
||||
{g.admin && <span className="badge bg-yellow-lt text-yellow ms-2">administrators</span>}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="d-flex flex-wrap align-items-center gap-2">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || groups === null}>
|
||||
{busy ? "Making…" : "Make user and link"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-link text-secondary" onClick={close} disabled={busy}>
|
||||
Cancel
|
||||
</button>
|
||||
<span className="text-secondary small">They choose their own password with the link; none is set here.</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+15
-10
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type AuthentikInfo } from "../api/client";
|
||||
import { api, type AuthentikInfo, type CurrentUser } from "../api/client";
|
||||
import AuthentikNewUser from "../components/AuthentikNewUser";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
@@ -22,7 +23,7 @@ function Left({ days, warn, critical }: { days: number; warn: number; critical:
|
||||
return <span className={days <= critical ? "text-red" : days <= warn ? "text-yellow" : "text-secondary"}>{text}</span>;
|
||||
}
|
||||
|
||||
function Card({ a }: { a: AuthentikInfo }) {
|
||||
function Card({ a, isAdmin, onChanged }: { a: AuthentikInfo; isAdmin: boolean; onChanged: () => void }) {
|
||||
const s = a.state;
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
@@ -126,34 +127,38 @@ function Card({ a }: { a: AuthentikInfo }) {
|
||||
{s.lastConfigError && <div className="text-secondary small">Latest configuration error: {s.lastConfigError}</div>}
|
||||
</>
|
||||
)}
|
||||
{isAdmin && a.enabled && <AuthentikNewUser a={a} onChanged={onChanged} />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Authentik, the front door: whether its outposts are reporting, what is about to run out, whether a worker is connected, and who is failing to sign in. */
|
||||
export default function Authentik() {
|
||||
export default function Authentik({ user }: { user: CurrentUser }) {
|
||||
const [data, setData] = useState<AuthentikInfo[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
const load = useCallback(
|
||||
() =>
|
||||
api.authentik
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.authentiks);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
.catch((err) => setError(readableError(err))),
|
||||
[],
|
||||
);
|
||||
useEffect(() => {
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
}, [load]);
|
||||
return (
|
||||
<>
|
||||
<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>.
|
||||
<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."}
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{!data && !error && <BlockSkeleton lines={4} />}
|
||||
@@ -164,7 +169,7 @@ export default function Authentik() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} />)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} isAdmin={user.role === "admin"} onChanged={() => void load()} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user