Events 2.3.0 (phase 1c): two-factor with an authenticator app, recovery codes
- TOTP (RFC 6238) next to email and WhatsApp: QR code and key to set up, the app's first code confirms it, a code can't be used twice, nothing is sent. The secret is stored encrypted. - 10 single-use recovery codes whenever two-factor is turned on, shown once; accepted at sign-in in place of any code; a new set on request. - Admins see each account's method; Reset 2FA clears the app and codes. - Profile & Security, sign-in and Users pages; API types; 10 new tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,7 @@ interface UserItem {
|
||||
phoneNumber?: string | null;
|
||||
notificationPreference?: string;
|
||||
twoFactorEnabled?: boolean;
|
||||
twoFactorMethod?: "email" | "whatsapp" | "authenticator" | null;
|
||||
isActive: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
@@ -34,6 +35,8 @@ type Role = typeof roleOptions[number];
|
||||
const notificationPreferenceOptions = ["email", "whatsapp", "both"] as const;
|
||||
|
||||
|
||||
const TWO_FACTOR_LABEL: Record<"email" | "whatsapp" | "authenticator", string> = { email: "email", whatsapp: "WhatsApp", authenticator: "app" };
|
||||
|
||||
export default function AdminUsersPage() {
|
||||
const { user, loading, token } = useAuth();
|
||||
const router = useRouter();
|
||||
@@ -418,6 +421,9 @@ export default function AdminUsersPage() {
|
||||
</td>
|
||||
<td className="p-2">
|
||||
<RoleBadge role={u.role as RoleBadgeRole} />
|
||||
<div className="mt-1 text-xs text-gray-500" title="How their sign-in codes come">
|
||||
{u.twoFactorEnabled ? `2FA: ${TWO_FACTOR_LABEL[u.twoFactorMethod || "email"]}` : "No 2FA"}
|
||||
</div>
|
||||
</td>
|
||||
<td className="p-2">
|
||||
<span>{u.phoneNumber || ""}</span>
|
||||
|
||||
@@ -14,17 +14,19 @@ import { useCampuses } from "@/hooks/useCampuses";
|
||||
import { apiV2, apiV2Data } from "@/lib/apiV2";
|
||||
import { useStateSync } from "@/lib/hooks";
|
||||
|
||||
type ActivityEvent = { id: string; type: "login" | "password_changed" | "password_reset" | "two_factor_enabled" | "two_factor_disabled"; device: string | null; createdAt: string };
|
||||
type ActivityEvent = { id: string; type: "login" | "password_changed" | "password_reset" | "two_factor_enabled" | "two_factor_disabled" | "recovery_code_used" | "recovery_codes_replaced"; device: string | null; createdAt: string };
|
||||
|
||||
const ACTIVITY_META: Record<ActivityEvent["type"], { label: (device: string | null) => string; icon: typeof LogIn }> = {
|
||||
login: { label: d => `Logged in${d ? ` from ${d}` : ""}`, icon: LogIn },
|
||||
password_changed: { label: () => "Password changed", icon: KeyRound },
|
||||
password_reset: { label: () => "Password reset via email link", icon: RotateCcw },
|
||||
two_factor_enabled: { label: () => "Two-factor authentication turned on", icon: ShieldCheck },
|
||||
recovery_code_used: { label: () => "Logged in with a recovery code", icon: ShieldAlert },
|
||||
recovery_codes_replaced: { label: () => "New recovery codes made", icon: ShieldCheck },
|
||||
two_factor_disabled: { label: () => "Two-factor authentication turned off", icon: ShieldOff },
|
||||
};
|
||||
|
||||
const TWO_FACTOR_METHOD_LABEL: Record<TwoFactorMethod, string> = { email: "email", whatsapp: "WhatsApp" };
|
||||
const TWO_FACTOR_METHOD_LABEL: Record<TwoFactorMethod, string> = { email: "email", whatsapp: "WhatsApp", authenticator: "an authenticator app" };
|
||||
|
||||
// Shared bits of the page (outside the component, so they aren't new components each render).
|
||||
const Alert = ({ msg }: { msg: { type: "ok" | "err"; text: string } }) => (
|
||||
@@ -185,12 +187,16 @@ export default function UserProfilePage() {
|
||||
// loaded once per page load, so it wouldn't reflect a change made here.
|
||||
const [tfEnabled, setTfEnabled] = useState(false);
|
||||
const [tfMethod, setTfMethod] = useState<TwoFactorMethod>("email");
|
||||
const [tfStep, setTfStep] = useState<"idle" | "code" | "disable" | "change">("idle");
|
||||
const [tfStep, setTfStep] = useState<"idle" | "code" | "disable" | "change" | "recovery">("idle");
|
||||
const [tfPassword, setTfPassword] = useState("");
|
||||
const [tfCode, setTfCode] = useState("");
|
||||
const [tfChallenge, setTfChallenge] = useState<TwoFactorChallenge | null>(null);
|
||||
const [tfMsg, setTfMsg] = useDismissingState<{ type: "ok" | "err"; text: string } | null>(null);
|
||||
const [tfBusy, setTfBusy] = useState(false);
|
||||
// 2.3.0: recovery codes just made (shown once), how many are left, and the setup QR code.
|
||||
const [tfRecovery, setTfRecovery] = useState<string[] | null>(null);
|
||||
const [tfRecoveryLeft, setTfRecoveryLeft] = useState(0);
|
||||
const [tfQr, setTfQr] = useState<{ url: string; image: string } | null>(null);
|
||||
|
||||
// WhatsApp codes need the number that's actually saved, not one still being typed.
|
||||
const canWhatsAppCodes = isValidZAPhone(user?.phoneNumber || "");
|
||||
@@ -201,9 +207,19 @@ export default function UserProfilePage() {
|
||||
if (user) {
|
||||
setTfEnabled(!!user.twoFactorEnabled);
|
||||
setTfMethod(user.twoFactorMethod || "email");
|
||||
setTfRecoveryLeft((user as { recoveryCodesLeft?: number }).recoveryCodesLeft ?? 0);
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
// The setup QR code, drawn here from the otpauth:// link (the key never leaves the browser).
|
||||
useEffect(() => {
|
||||
const url = tfChallenge?.otpauthUrl;
|
||||
if (!url) return;
|
||||
let alive = true;
|
||||
import("qrcode").then(q => q.toDataURL(url, { margin: 1, width: 200 })).then(image => { if (alive) setTfQr({ url, image }); }).catch(() => {});
|
||||
return () => { alive = false; };
|
||||
}, [tfChallenge]);
|
||||
|
||||
const resetTwoFactorForm = () => {
|
||||
setTfStep("idle");
|
||||
setTfPassword("");
|
||||
@@ -241,12 +257,14 @@ export default function UserProfilePage() {
|
||||
const res = await (apiV2Data("post", "/me/two-factor/confirm", {
|
||||
authToken: token,
|
||||
body: { challengeId: tfChallenge.challengeId, code: tfCode },
|
||||
}) as Promise<{ twoFactorMethod: TwoFactorMethod }>);
|
||||
}) as Promise<{ twoFactorMethod: TwoFactorMethod; recoveryCodes?: string[] }>);
|
||||
const wasEnabled = tfEnabled;
|
||||
setTfEnabled(true);
|
||||
setTfMethod(res.twoFactorMethod);
|
||||
resetTwoFactorForm();
|
||||
setTfMsg({ type: "ok", text: wasEnabled ? `Codes will now be sent by ${TWO_FACTOR_METHOD_LABEL[res.twoFactorMethod]}.` : "Two-factor authentication is on." });
|
||||
setTfRecovery(res.recoveryCodes ?? null);
|
||||
setTfRecoveryLeft(res.recoveryCodes?.length ?? 0);
|
||||
setTfMsg({ type: "ok", text: wasEnabled ? `Your codes now come from ${TWO_FACTOR_METHOD_LABEL[res.twoFactorMethod]}.` : "Two-factor authentication is on." });
|
||||
loadActivity();
|
||||
} catch (e) {
|
||||
setTfMsg({ type: "err", text: errorMessage(e) || "Failed to verify the code." });
|
||||
@@ -255,6 +273,35 @@ export default function UserProfilePage() {
|
||||
}
|
||||
};
|
||||
|
||||
const newRecoveryCodes = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!token) return;
|
||||
setTfBusy(true);
|
||||
setTfMsg(null);
|
||||
try {
|
||||
const res = await (apiV2Data("post", "/me/two-factor/recovery-codes", { authToken: token, body: { password: tfPassword } }) as Promise<{ recoveryCodes: string[] }>);
|
||||
resetTwoFactorForm();
|
||||
setTfRecovery(res.recoveryCodes);
|
||||
setTfRecoveryLeft(res.recoveryCodes.length);
|
||||
loadActivity();
|
||||
} catch (e) {
|
||||
setTfMsg({ type: "err", text: errorMessage(e) || "Couldn't make new recovery codes." });
|
||||
} finally {
|
||||
setTfBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const downloadRecovery = () => {
|
||||
if (!tfRecovery) return;
|
||||
const text = `Recovery codes for ${user?.email || "your account"} (${window.location.host})\nEach works once, in place of a code, if you lose your phone or app.\n\n${tfRecovery.join("\n")}\n`;
|
||||
const url = URL.createObjectURL(new Blob([text], { type: "text/plain" }));
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = "recovery-codes.txt";
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const disableTwoFactor = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!token) return;
|
||||
@@ -266,6 +313,7 @@ export default function UserProfilePage() {
|
||||
body: { password: tfPassword },
|
||||
});
|
||||
setTfEnabled(false);
|
||||
setTfRecoveryLeft(0);
|
||||
resetTwoFactorForm();
|
||||
setTfMsg({ type: "ok", text: "Two-factor authentication is off." });
|
||||
loadActivity();
|
||||
@@ -424,9 +472,20 @@ export default function UserProfilePage() {
|
||||
|
||||
{tfStep === "code" && tfChallenge ? (
|
||||
<form onSubmit={confirmEnableTwoFactor} className="space-y-4">
|
||||
<p className="text-sm text-gray-500">
|
||||
We sent a 6-digit code to {tfChallenge.destination} by {TWO_FACTOR_METHOD_LABEL[tfChallenge.method]}. {tfEnabled ? "Enter it to switch your codes to this channel." : "Enter it to finish turning on two-factor authentication."}
|
||||
</p>
|
||||
{tfChallenge.method === "authenticator" ? (
|
||||
<div className="space-y-3 text-sm text-gray-600">
|
||||
<p>Scan this with an authenticator app (Google Authenticator, Microsoft Authenticator, 1Password, Authy…), then enter the 6-digit code it shows.</p>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element -- a data: URL drawn in the browser */}
|
||||
{tfQr && tfQr.url === tfChallenge.otpauthUrl && <img src={tfQr.image} alt="QR code to add this account to an authenticator app" width={200} height={200} className="rounded border" />}
|
||||
{tfChallenge.secret && (
|
||||
<p className="text-xs">Can't scan it? Type this key into the app: <code className="select-all break-all rounded bg-gray-100 px-1 py-0.5 font-mono">{tfChallenge.secret.replace(/(.{4})/g, "$1 ").trim()}</code></p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-gray-500">
|
||||
We sent a 6-digit code to {tfChallenge.destination} by {TWO_FACTOR_METHOD_LABEL[tfChallenge.method]}. {tfEnabled ? "Enter it to switch your codes to this channel." : "Enter it to finish turning on two-factor authentication."}
|
||||
</p>
|
||||
)}
|
||||
<div>
|
||||
<label htmlFor="profile-verification-code" className="block text-sm font-medium text-gray-700 mb-1">Verification code</label>
|
||||
<input
|
||||
@@ -446,16 +505,32 @@ export default function UserProfilePage() {
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" disabled={tfBusy || tfCode.length !== 6} className="px-4 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">
|
||||
{tfBusy ? "Verifying…" : "Turn on two-factor"}
|
||||
{tfBusy ? "Verifying…" : tfEnabled ? "Switch" : "Turn on two-factor"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
) : tfEnabled && tfStep !== "change" ? (
|
||||
<>
|
||||
<p className="text-sm text-gray-500 mb-4">
|
||||
<span className="font-medium text-green-700">On.</span> When you log in we send a 6-digit code by{" "}
|
||||
{TWO_FACTOR_METHOD_LABEL[tfMethod]}. Devices you've chosen to trust skip the code for 30 days.
|
||||
<span className="font-medium text-green-700">On.</span>{" "}
|
||||
{tfMethod === "authenticator" ? "When you log in, enter the 6-digit code from your authenticator app." : <>When you log in we send a 6-digit code by {TWO_FACTOR_METHOD_LABEL[tfMethod]}.</>}{" "}
|
||||
Devices you've chosen to trust skip the code for 30 days.
|
||||
</p>
|
||||
<div className="mb-4 rounded-lg border border-gray-200 bg-gray-50 p-3 text-sm">
|
||||
<p className="text-gray-700"><span className="font-medium">Recovery codes:</span> {tfRecoveryLeft} of 10 left. Each works once in place of a code if you lose your phone or app.</p>
|
||||
{tfStep === "recovery" ? (
|
||||
<form onSubmit={newRecoveryCodes} className="mt-3 flex flex-wrap items-end gap-2">
|
||||
<div className="flex-1 min-w-[12rem]">
|
||||
<label htmlFor="profile-recovery-password" className="block text-xs font-medium text-gray-700 mb-1">Confirm with your password</label>
|
||||
<input id="profile-recovery-password" type="password" className={inputCls} value={tfPassword} onChange={e => setTfPassword(e.target.value)} required autoComplete="current-password" />
|
||||
</div>
|
||||
<button type="button" onClick={resetTwoFactorForm} className="px-3 py-2 rounded-lg bg-gray-100 text-sm font-medium hover:bg-gray-200">Cancel</button>
|
||||
<button type="submit" disabled={tfBusy || !tfPassword} className="px-3 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">{tfBusy ? "Making…" : "Make new codes"}</button>
|
||||
</form>
|
||||
) : (
|
||||
<button onClick={() => { setTfStep("recovery"); setTfPassword(""); setTfMsg(null); }} className="mt-2 text-sm text-brand-700 hover:underline">New recovery codes…</button>
|
||||
)}
|
||||
</div>
|
||||
{tfRequired ? (
|
||||
<>
|
||||
<p className="text-xs text-gray-500 mb-3">Required for your role, so it can't be turned off.</p>
|
||||
@@ -495,11 +570,12 @@ export default function UserProfilePage() {
|
||||
<p className="text-sm text-gray-500">
|
||||
{tfEnabled
|
||||
? "Choose where your login codes go. We'll send a code there first to check it reaches you."
|
||||
: "Add a second step to logging in: after your password, we send a 6-digit code that you need to enter."}
|
||||
: "Add a second step to logging in: after your password, a 6-digit code from an authenticator app, or one we send you."}
|
||||
</p>
|
||||
<div>
|
||||
<label htmlFor="profile-send-my-codes-by" className="block text-sm font-medium text-gray-700 mb-1">Send my codes by</label>
|
||||
<select id="profile-send-my-codes-by" className={inputCls} value={tfMethod} onChange={e => setTfMethod(e.target.value as TwoFactorMethod)}>
|
||||
<option value="authenticator">An authenticator app (most secure)</option>
|
||||
<option value="email">Email</option>
|
||||
{canWhatsAppCodes && <option value="whatsapp">WhatsApp</option>}
|
||||
</select>
|
||||
@@ -518,11 +594,23 @@ export default function UserProfilePage() {
|
||||
</button>
|
||||
)}
|
||||
<button type="submit" disabled={tfBusy || !tfPassword} className="px-4 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">
|
||||
{tfBusy ? "Sending code…" : "Send verification code"}
|
||||
{tfBusy ? (tfMethod === "authenticator" ? "Preparing…" : "Sending code…") : tfMethod === "authenticator" ? "Set up the app" : "Send verification code"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
{tfRecovery && (
|
||||
<div className="mt-4 rounded-lg border border-amber-300 bg-amber-50 p-4 text-sm" role="region" aria-label="Your recovery codes">
|
||||
<p className="font-medium text-amber-900">Save your recovery codes now</p>
|
||||
<p className="mt-1 text-amber-900">Each works once, in place of a code, if you lose your phone or app. They won't be shown again.</p>
|
||||
<ul className="mt-3 grid grid-cols-2 gap-x-6 gap-y-1 font-mono text-sm sm:grid-cols-3">{tfRecovery.map(c => <li key={c}>{c}</li>)}</ul>
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
<button type="button" onClick={downloadRecovery} className="px-3 py-2 rounded-lg bg-white border border-amber-300 text-sm font-medium hover:bg-amber-100">Download</button>
|
||||
<button type="button" onClick={() => navigator.clipboard?.writeText(tfRecovery.join("\n"))} className="px-3 py-2 rounded-lg bg-white border border-amber-300 text-sm font-medium hover:bg-amber-100">Copy</button>
|
||||
<button type="button" onClick={() => setTfRecovery(null)} className="px-3 py-2 rounded-lg bg-amber-600 text-white text-sm font-medium hover:bg-amber-700">I've saved them</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{tfMsg && <Alert msg={tfMsg} />}
|
||||
</section>
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ export function LoginForm() {
|
||||
// Two-factor step — set once the password is accepted for an account with 2FA on.
|
||||
const [challenge, setChallenge] = useState<TwoFactorChallenge | null>(null);
|
||||
const [code, setCode] = useState("");
|
||||
// 2.3.0: a recovery code instead of the 6-digit code (xxxxx-xxxxx, single use).
|
||||
const [useRecovery, setUseRecovery] = useState(false);
|
||||
const [rememberDevice, setRememberDevice] = useState(false);
|
||||
const [resendIn, setResendIn] = useState(0);
|
||||
|
||||
@@ -109,6 +111,7 @@ export function LoginForm() {
|
||||
const backToPassword = () => {
|
||||
setChallenge(null);
|
||||
setCode("");
|
||||
setUseRecovery(false);
|
||||
setPassword("");
|
||||
setError(null);
|
||||
};
|
||||
@@ -124,20 +127,24 @@ export function LoginForm() {
|
||||
</p>
|
||||
)}
|
||||
<p className="text-sm text-gray-600 mt-1">
|
||||
We sent a 6-digit code to {challenge.destination} by {challenge.method === "whatsapp" ? "WhatsApp" : "email"}. It expires in 10 minutes.
|
||||
{useRecovery
|
||||
? "Enter one of the recovery codes you saved when you turned on two-factor. Each works once."
|
||||
: challenge.method === "authenticator"
|
||||
? "Open your authenticator app and enter the 6-digit code it shows for this site."
|
||||
: <>We sent a 6-digit code to {challenge.destination} by {challenge.method === "whatsapp" ? "WhatsApp" : "email"}. It expires in 10 minutes.</>}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="login-code" className="block text-sm font-medium mb-1">Verification code</label>
|
||||
<label htmlFor="login-code" className="block text-sm font-medium mb-1">{useRecovery ? "Recovery code" : "Verification code"}</label>
|
||||
<input
|
||||
id="login-code"
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
autoComplete="one-time-code"
|
||||
maxLength={6}
|
||||
inputMode={useRecovery ? "text" : "numeric"}
|
||||
autoComplete={useRecovery ? "off" : "one-time-code"}
|
||||
maxLength={useRecovery ? 11 : 6}
|
||||
value={code}
|
||||
onChange={(e) => setCode(e.target.value.replace(/\D/g, ""))}
|
||||
onChange={(e) => setCode(useRecovery ? e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, "") : e.target.value.replace(/\D/g, ""))}
|
||||
className="w-full border rounded px-3 py-2 text-lg tracking-widest"
|
||||
autoFocus
|
||||
required
|
||||
@@ -158,7 +165,7 @@ export function LoginForm() {
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading || code.length !== 6}
|
||||
disabled={loading || (useRecovery ? code.replace(/-/g, "").length !== 10 : code.length !== 6)}
|
||||
className="w-full bg-brand-600 hover:bg-brand-700 text-white rounded py-2 disabled:opacity-60"
|
||||
>
|
||||
{loading ? "Verifying..." : "Verify and log in"}
|
||||
@@ -168,14 +175,21 @@ export function LoginForm() {
|
||||
<button type="button" onClick={backToPassword} className="text-brand-600 hover:underline">
|
||||
Back to login
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onResend}
|
||||
disabled={resendIn > 0}
|
||||
className="text-brand-600 hover:underline disabled:text-gray-400 disabled:no-underline"
|
||||
>
|
||||
{resendIn > 0 ? `Resend code in ${resendIn}s` : "Resend code"}
|
||||
</button>
|
||||
{!challenge.enrolling && (
|
||||
<button type="button" onClick={() => { setUseRecovery(!useRecovery); setCode(""); setError(null); }} className="text-brand-600 hover:underline">
|
||||
{useRecovery ? "Use a code instead" : "Use a recovery code"}
|
||||
</button>
|
||||
)}
|
||||
{challenge.method !== "authenticator" && !useRecovery && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onResend}
|
||||
disabled={resendIn > 0}
|
||||
className="text-brand-600 hover:underline disabled:text-gray-400 disabled:no-underline"
|
||||
>
|
||||
{resendIn > 0 ? `Resend code in ${resendIn}s` : "Resend code"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
|
||||
@@ -12950,6 +12950,28 @@
|
||||
"type": "boolean",
|
||||
"description": "Their role must use two-step sign-in"
|
||||
},
|
||||
"twoFactorMethod": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"email",
|
||||
"whatsapp",
|
||||
"authenticator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "How their codes come (2.3.0: authenticator = an app)"
|
||||
},
|
||||
"recoveryCodesLeft": {
|
||||
"type": "integer",
|
||||
"minimum": -9007199254740991,
|
||||
"maximum": 9007199254740991,
|
||||
"description": "Unused recovery codes (0 with two-step sign-in off)"
|
||||
},
|
||||
"newsPromptPending": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -12995,6 +13017,8 @@
|
||||
"homeCampusId",
|
||||
"createdAt",
|
||||
"twoFactorRequired",
|
||||
"twoFactorMethod",
|
||||
"recoveryCodesLeft",
|
||||
"newsPromptPending",
|
||||
"noticePromptPending",
|
||||
"campusScope"
|
||||
@@ -47764,7 +47788,8 @@
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"email",
|
||||
"whatsapp"
|
||||
"whatsapp",
|
||||
"authenticator"
|
||||
]
|
||||
},
|
||||
"destination": {
|
||||
@@ -48395,7 +48420,7 @@
|
||||
"Me"
|
||||
],
|
||||
"summary": "Start turning on two-step sign-in",
|
||||
"description": "Sends a code to confirm with.\n\n**Who:** Any signed-in person.",
|
||||
"description": "Sends a code to confirm with, or for `authenticator` (2.3.0) answers with `secret` and `otpauthUrl` to show as a QR code; the app's first code confirms it.\n\n**Who:** Any signed-in person.",
|
||||
"operationId": "postMeTwo-factorEnable",
|
||||
"security": [
|
||||
{
|
||||
@@ -48414,7 +48439,8 @@
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"email",
|
||||
"whatsapp"
|
||||
"whatsapp",
|
||||
"authenticator"
|
||||
]
|
||||
},
|
||||
"password": {
|
||||
@@ -48448,12 +48474,27 @@
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"email",
|
||||
"whatsapp"
|
||||
"whatsapp",
|
||||
"authenticator"
|
||||
]
|
||||
},
|
||||
"destination": {
|
||||
"type": "string",
|
||||
"description": "Where the code went, partly hidden"
|
||||
},
|
||||
"secret": {
|
||||
"description": "authenticator: the key to type in by hand",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"otpauthUrl": {
|
||||
"description": "authenticator: show as a QR code",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -48549,11 +48590,107 @@
|
||||
},
|
||||
"twoFactorMethod": {
|
||||
"type": "string"
|
||||
},
|
||||
"recoveryCodes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "Shown once: single-use codes for when the app or phone is lost"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"twoFactorEnabled",
|
||||
"twoFactorMethod"
|
||||
"twoFactorMethod",
|
||||
"recoveryCodes"
|
||||
],
|
||||
"additionalProperties": {}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Validation failed (VALIDATION_FAILED)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Not signed in (UNAUTHENTICATED)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/me/two-factor/recovery-codes": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"Me"
|
||||
],
|
||||
"summary": "A new set of recovery codes",
|
||||
"description": "Needs the password. The old codes stop working; the new ones are shown once.\n\n**Who:** Any signed-in person.",
|
||||
"operationId": "postMeTwo-factorRecovery-codes",
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
],
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"password"
|
||||
],
|
||||
"additionalProperties": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"recoveryCodes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"recoveryCodes"
|
||||
],
|
||||
"additionalProperties": {}
|
||||
}
|
||||
@@ -48975,6 +49112,28 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"twoFactorEnabled": {
|
||||
"type": [
|
||||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"twoFactorMethod": {
|
||||
"description": "How their sign-in codes come (2.3.0: authenticator = an app)",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"email",
|
||||
"whatsapp",
|
||||
"authenticator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"homeCampusId": {
|
||||
"type": [
|
||||
"string",
|
||||
@@ -49148,6 +49307,28 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"twoFactorEnabled": {
|
||||
"type": [
|
||||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"twoFactorMethod": {
|
||||
"description": "How their sign-in codes come (2.3.0: authenticator = an app)",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"email",
|
||||
"whatsapp",
|
||||
"authenticator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"homeCampusId": {
|
||||
"type": [
|
||||
"string",
|
||||
@@ -49385,6 +49566,28 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"twoFactorEnabled": {
|
||||
"type": [
|
||||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"twoFactorMethod": {
|
||||
"description": "How their sign-in codes come (2.3.0: authenticator = an app)",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"email",
|
||||
"whatsapp",
|
||||
"authenticator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"homeCampusId": {
|
||||
"type": [
|
||||
"string",
|
||||
|
||||
+97
-4
@@ -4787,7 +4787,7 @@ export interface paths {
|
||||
put?: never;
|
||||
/**
|
||||
* Start turning on two-step sign-in
|
||||
* @description Sends a code to confirm with.
|
||||
* @description Sends a code to confirm with, or for `authenticator` (2.3.0) answers with `secret` and `otpauthUrl` to show as a QR code; the app's first code confirms it.
|
||||
*
|
||||
* **Who:** Any signed-in person.
|
||||
*/
|
||||
@@ -4818,6 +4818,28 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/me/two-factor/recovery-codes": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* A new set of recovery codes
|
||||
* @description Needs the password. The old codes stop working; the new ones are shown once.
|
||||
*
|
||||
* **Who:** Any signed-in person.
|
||||
*/
|
||||
post: operations["postMeTwo-factorRecovery-codes"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/me/two-factor/disable": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -12787,6 +12809,10 @@ export interface operations {
|
||||
createdAt: string;
|
||||
/** @description Their role must use two-step sign-in */
|
||||
twoFactorRequired: boolean;
|
||||
/** @description How their codes come (2.3.0: authenticator = an app) */
|
||||
twoFactorMethod: ("email" | "whatsapp" | "authenticator") | null;
|
||||
/** @description Unused recovery codes (0 with two-step sign-in off) */
|
||||
recoveryCodesLeft: number;
|
||||
newsPromptPending: boolean;
|
||||
noticePromptPending: false | ("first" | "updated");
|
||||
campusScope: string[] | null;
|
||||
@@ -28100,7 +28126,7 @@ export interface operations {
|
||||
data: {
|
||||
challengeId: string;
|
||||
/** @enum {string} */
|
||||
method: "email" | "whatsapp";
|
||||
method: "email" | "whatsapp" | "authenticator";
|
||||
/** @description Where the code went, partly hidden */
|
||||
destination: string;
|
||||
} & {
|
||||
@@ -28472,7 +28498,7 @@ export interface operations {
|
||||
content: {
|
||||
"application/json": {
|
||||
/** @enum {string} */
|
||||
method: "email" | "whatsapp";
|
||||
method: "email" | "whatsapp" | "authenticator";
|
||||
password: string;
|
||||
} & {
|
||||
[key: string]: unknown;
|
||||
@@ -28490,9 +28516,13 @@ export interface operations {
|
||||
data: {
|
||||
challengeId: string;
|
||||
/** @enum {string} */
|
||||
method: "email" | "whatsapp";
|
||||
method: "email" | "whatsapp" | "authenticator";
|
||||
/** @description Where the code went, partly hidden */
|
||||
destination: string;
|
||||
/** @description authenticator: the key to type in by hand */
|
||||
secret?: string | null;
|
||||
/** @description authenticator: show as a QR code */
|
||||
otpauthUrl?: string | null;
|
||||
} & {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
@@ -28548,6 +28578,60 @@ export interface operations {
|
||||
/** @constant */
|
||||
twoFactorEnabled: true;
|
||||
twoFactorMethod: string;
|
||||
/** @description Shown once: single-use codes for when the app or phone is lost */
|
||||
recoveryCodes: string[];
|
||||
} & {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Validation failed (VALIDATION_FAILED) */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description Not signed in (UNAUTHENTICATED) */
|
||||
401: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"postMeTwo-factorRecovery-codes": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": {
|
||||
password: string;
|
||||
} & {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description OK */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
recoveryCodes: string[];
|
||||
} & {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
@@ -28738,6 +28822,9 @@ export interface operations {
|
||||
role: "admin" | "supervisor" | "staff" | "user";
|
||||
isActive?: boolean | null;
|
||||
notificationPreference?: ("email" | "whatsapp" | "both") | null;
|
||||
twoFactorEnabled?: boolean | null;
|
||||
/** @description How their sign-in codes come (2.3.0: authenticator = an app) */
|
||||
twoFactorMethod?: ("email" | "whatsapp" | "authenticator") | null;
|
||||
homeCampusId?: string | null;
|
||||
createdAt?: string | null;
|
||||
} & {
|
||||
@@ -28810,6 +28897,9 @@ export interface operations {
|
||||
role: "admin" | "supervisor" | "staff" | "user";
|
||||
isActive?: boolean | null;
|
||||
notificationPreference?: ("email" | "whatsapp" | "both") | null;
|
||||
twoFactorEnabled?: boolean | null;
|
||||
/** @description How their sign-in codes come (2.3.0: authenticator = an app) */
|
||||
twoFactorMethod?: ("email" | "whatsapp" | "authenticator") | null;
|
||||
homeCampusId?: string | null;
|
||||
createdAt?: string | null;
|
||||
/** @description Campuses they're limited to */
|
||||
@@ -28972,6 +29062,9 @@ export interface operations {
|
||||
role: "admin" | "supervisor" | "staff" | "user";
|
||||
isActive?: boolean | null;
|
||||
notificationPreference?: ("email" | "whatsapp" | "both") | null;
|
||||
twoFactorEnabled?: boolean | null;
|
||||
/** @description How their sign-in codes come (2.3.0: authenticator = an app) */
|
||||
twoFactorMethod?: ("email" | "whatsapp" | "authenticator") | null;
|
||||
homeCampusId?: string | null;
|
||||
createdAt?: string | null;
|
||||
} & {
|
||||
|
||||
@@ -26,7 +26,7 @@ export type AuthResponse = AuthUser & {
|
||||
deviceToken?: string;
|
||||
};
|
||||
|
||||
export type TwoFactorMethod = "email" | "whatsapp";
|
||||
export type TwoFactorMethod = "email" | "whatsapp" | "authenticator";
|
||||
|
||||
// What the login endpoint returns instead of a token when the account has 2FA on:
|
||||
// a code was sent to `destination` (masked) and must be exchanged for the token.
|
||||
@@ -37,6 +37,9 @@ export type TwoFactorChallenge = {
|
||||
destination: string;
|
||||
// The role requires 2FA and it wasn't on yet: verifying this code turns it on.
|
||||
enrolling?: boolean;
|
||||
// 2.3.0, setting up an authenticator app: the key and its otpauth:// link (shown as a QR code).
|
||||
secret?: string;
|
||||
otpauthUrl?: string;
|
||||
};
|
||||
|
||||
export function isTwoFactorChallenge(res: unknown): res is TwoFactorChallenge {
|
||||
|
||||
Reference in New Issue
Block a user