Profile accounts: invites, any-Google sign-in, claiming People, visibility, Discord
Migration 076 adds a member role below viewer (the site and its own profile, never the admin: /api/admin now needs viewer), invites, person claims, a Discord link on accounts and people.hide_* switches. Public reads of people go through v_people_public, which nulls hidden fields, and the views that read people are rebuilt over it. Admins invite an email from Data -> Profile accounts (link shown once, emailed on request). The invitee sets a password or signs in with any Google account under that email, asks to claim their People record, and once approved edits it and chooses what shows at /account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0cc2a3f721
commit
e4c7e165d1
34 changed files with 2483 additions and 74 deletions
|
|
@ -30,6 +30,12 @@
|
|||
Nothing here creates an account. A Google login is only let in
|
||||
if admin-cli has already made one for that email (see auth.js
|
||||
routes), and is linked to it on first use.
|
||||
|
||||
Profile accounts (076) are the one case outside the domain: an
|
||||
invited member may sign in with any Google account under the
|
||||
invited email. finishLogin says whether the identity is in the
|
||||
Workspace domain (inDomain) instead of refusing it, and the
|
||||
callback lets an outside identity reach a member account only.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
|
|
@ -70,8 +76,10 @@ export function googleConfig() {
|
|||
}
|
||||
|
||||
/* The first leg: where to send the browser, and the state and PKCE
|
||||
verifier to keep (in a short-lived cookie) until it comes back. */
|
||||
export function startLogin(config) {
|
||||
verifier to keep (in a short-lived cookie) until it comes back.
|
||||
anyDomain: a profile account's sign-in, so the account chooser
|
||||
isn't narrowed to the Workspace. */
|
||||
export function startLogin(config, { anyDomain = false } = {}) {
|
||||
const state = base64url(randomBytes(24));
|
||||
const verifier = base64url(randomBytes(48));
|
||||
const challenge = base64url(createHash("sha256").update(verifier).digest());
|
||||
|
|
@ -87,7 +95,7 @@ export function startLogin(config) {
|
|||
code_challenge_method: "S256",
|
||||
// Only a hint to Google's account chooser; the hd claim is what's
|
||||
// actually checked on the way back.
|
||||
hd: config.domain,
|
||||
...(anyDomain ? {} : { hd: config.domain }),
|
||||
prompt: "select_account",
|
||||
});
|
||||
|
||||
|
|
@ -102,7 +110,7 @@ export class GoogleLoginError extends Error {
|
|||
}
|
||||
|
||||
/* The second leg: trade the code for tokens and check the identity.
|
||||
Returns { sub, email, name } or throws GoogleLoginError. */
|
||||
Returns { sub, email, name, inDomain } or throws GoogleLoginError. */
|
||||
export async function finishLogin(config, code, verifier) {
|
||||
let res;
|
||||
try {
|
||||
|
|
@ -145,9 +153,7 @@ export async function finishLogin(config, code, verifier) {
|
|||
if (!claims.email_verified || !email) {
|
||||
throw new GoogleLoginError("unverified", "That Google account's email isn't verified.");
|
||||
}
|
||||
if (String(claims.hd ?? "").toLowerCase() !== config.domain || !email.endsWith(`@${config.domain}`)) {
|
||||
throw new GoogleLoginError("wrong_domain", `Use your @${config.domain} account.`);
|
||||
}
|
||||
const inDomain = String(claims.hd ?? "").toLowerCase() === config.domain && email.endsWith(`@${config.domain}`);
|
||||
|
||||
return { sub: String(claims.sub), email, name: claims.name ?? null };
|
||||
return { sub: String(claims.sub), email, name: claims.name ?? null, inDomain };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue