Skip to content
Myr

Merge auth/sign-in-redesign into main

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by oscabriel · committed by oscabriel · parents b9fc54b, 2d841e7 · Browse files · 12 files+478 added−103 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

12 files+478 added−103 removed

  • tests:+213 added−11 removed
  • other:+265 added−92 removed

12 files+478 added−103 removed

modified:apps/cli/src/local/login.ts+31 added-2 removed
285 unmodified lines
286 Effect.flatMap((digest) => encodeBase64Url(new Uint8Array(digest))),287 Effect.orDie288 );289290// The browser's last stop, in the sign-in pages' look: their paper, ink and291// muted values, light and dark, and nothing loaded. The text is fixed, so292// nothing in it needs escaping.293const callbackPage = (title: string, line: string) => `<!doctype html>294<html lang="en">295<head>296<meta charset="utf-8">297<meta name="viewport" content="width=device-width, initial-scale=1">298<meta name="color-scheme" content="light dark">299<title>${title} · ${Brand.name}</title>300<style>301:root{color-scheme:light dark;--paper:#f8f7f4;--ink:#1a1f2e;--muted:#5d6371}302@media (prefers-color-scheme:dark){:root{--paper:#0a0a0a;--ink:#f5f5f5;--muted:#a0a0a0}}303body{margin:0;background-color:var(--paper);color:var(--ink);font-family:"IBM Plex Sans",ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-size:16px;line-height:1.5}304main{max-width:25rem;margin:0 auto;padding:20vh 16px 48px;text-align:center}305.wordmark{margin:0 0 28px;font-size:1.1875rem;font-weight:600;letter-spacing:-.02em}306h1{margin:0 0 8px;font-size:1.5rem;line-height:2rem;font-weight:600;letter-spacing:-.015em}307p{margin:0;color:var(--muted)}308p.wordmark{color:var(--ink)}309</style>310</head>311<body><main><p class="wordmark">${Brand.name}</p><h1>${title}</h1><p>${line}</p></main></body>312</html>313`;314315const loopback = Effect.gen(function* () {316 const { listen } = yield* Loopback;317 const server = yield* listen({ hostname: LOOPBACK, port: 0 });318 const returned = yield* Deferred.make<URLSearchParams>();
10 unmodified lines
329 const first = yield* Deferred.succeed(returned, at.searchParams);330331 return HttpServerResponse.text(332 first308 ? `${Brand.cli} login has the sign-in. You can close this tab; the terminal says how it ended.`309 : "This sign-in has already come back.",333 ? callbackPage(334 "Signed in",335 "You can close this tab and go back to your terminal."336 )337 : callbackPage("Already signed in", "This sign-in already finished."),338 {339 contentType: "text/html; charset=utf-8",340 // One request per connection, so closing the server waits on none.341 headers: { "cache-control": "no-store", connection: "close" },342 status: first ? 200 : 410,343 }
342 unmodified lines
modified:apps/cli/test/local/login.test.ts+26 added-1 removed
247 unmodified lines
248249 return response.status;250 }).pipe(Effect.provide(FetchHttpClient.layer));251252/** What the browser is shown at the end: the callback's page. */253const landing = (at: string) =>254 Effect.gen(function* () {255 const client = yield* HttpClient.HttpClient;256 const response = yield* client.get(at);257258 return {259 status: response.status,260 text: yield* response.text,261 type: response.headers["content-type"],262 };263 }).pipe(Effect.provide(FetchHttpClient.layer));264265const fieldsOf = (query: URLSearchParams | undefined) =>266 Object.fromEntries(query?.entries() ?? []);267268describe(`${Brand.cli} login --token-stdin`, () => {
295 unmodified lines
564 { env, seams: platform.layer }565 )566 );567555 expect(yield* visit(yield* signInUrl(server.origin))).toBe(200);568 const shown = yield* landing(yield* signInUrl(server.origin));569570 expect({571 said: shown.text.includes(572 "You can close this tab and go back to your terminal."573 ),574 status: shown.status,575 type: shown.type,576 }).toStrictEqual({577 said: true,578 status: 200,579 type: "text/html; charset=utf-8",580 });581 expect(Exit.isSuccess(yield* Fiber.join(fiber))).toBeTruthy();582583 const [query] = yield* server.authorizations;584 const fields = fieldsOf(query);
257 unmodified lines
added:apps/platform/src/auth/first-party.ts+31 added
modified:apps/platform/src/auth/google.ts+2 added
43 unmodified lines
44 HeldHandles,45 htmlPage,46 Says,47 SignInKeys,48 SignInHome,49 SignInOffers,50 signInPageFor,51} from "./sign-in.ts";52import type { SignInServices } from "./sign-in.ts";
781 unmodified lines
834 Context.add(Identities, yield* Identities),835 Context.add(Mailer, yield* Mailer),836 Context.add(OAuthStore, yield* OAuthStore),837 Context.add(SignInAttempts, yield* SignInAttempts),838 Context.add(SignInHome, yield* SignInHome),839 Context.add(SignInKeys, yield* SignInKeys),840 Context.add(SignInOffers, yield* SignInOffers)841 );842
20 unmodified lines
modified:apps/platform/src/auth/pages.ts+157 added-82 removed
1// Loads nothing (no script, stylesheet, font or image), so the page's CSP can be `default-src 'none'`.2import { Brand } from "@repo/brand";34import type { FirstParty } from "./first-party.ts";56export interface Asker {7 readonly clientDomain?: string | undefined;8 readonly clientName: string;9 readonly redirectHost: string;10 readonly redirectIsLoopback: boolean;11 // Our own web or CLI, told by the client's id: neither is asked to consent.12 readonly firstParty?: FirstParty | undefined;13 // The web's home, which the wordmark links to; the platform's `/` when it is not known.14 readonly home?: string | undefined;15}1617export interface PendingForm {18 readonly csrf: string;
28 unmodified lines
47 .replaceAll(">", "&gt;")48 .replaceAll('"', "&quot;")49 .replaceAll("'", "&#39;");5045// The web's focus shell, drawn without its code: the sage garden palette's51// The web's focus card, drawn without its code: the sage garden palette's52// values copied from apps/web/src/styles.css as hex (the paper, ink, rule,53// muted, input, primary and state roles, light and dark), and its faces named54// first. No font may load here, so IBM Plex is used where the reader has it49// installed and the system's faces stand in otherwise. The frame is the50// web's: from 640 px a hairline down each edge of the card's container, the51// page's full height, with the wordmark's bar a box between them under a52// 16 px gap (DESIGN.md "Rails"); on a phone the bar's rule alone.55// installed and the system's faces stand in otherwise. One centred column of56// the card's width: the wordmark over the card, and what leads elsewhere57// under it. From 640 px the card is a hairline-bordered surface on the paper;58// on a phone it is the page itself, with no border to box it in.59const STYLE = `60:root{color-scheme:light dark;--paper:#f8f7f4;--ink:#1a1f2e;--card:#ffffff;--surface:#e8e6e1;--muted:#5d6371;--rule:#d6d4cf;--input:#79808f;--primary:#677a6d;--on-primary:#ffffff;--refused:#ae2325;--waiting:#516012;--selection:#0c628c38}61@media (prefers-color-scheme:dark){:root{--paper:#0a0a0a;--ink:#f5f5f5;--card:#121212;--surface:#1a1a1a;--muted:#a0a0a0;--rule:#2a2a2a;--input:#696969;--primary:#7c9082;--on-primary:#000000;--refused:#ff5451;--waiting:#bad074;--selection:#68bbef38}}62*{box-sizing:border-box}63body{margin:0;background-color:var(--paper);color:var(--ink);caret-color:var(--ink);font-family:"IBM Plex Sans",ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-size:16px;line-height:1.5;-webkit-text-size-adjust:100%;text-size-adjust:100%}64::selection{background-color:var(--selection);color:var(--ink)}59.frame{display:flex;flex-direction:column;min-height:100dvh;max-width:25rem;margin:0 auto}60.top{display:flex;align-items:center;height:56px;padding:0 16px;border-bottom:1px solid var(--rule)}61.wordmark{margin:0;font-size:1rem;line-height:1.5rem;font-weight:600;letter-spacing:-.015em}62main{padding:32px 16px 64px}63main.document{max-width:44rem;margin:0 auto;padding-top:48px}64@media (min-width:40em){.frame{border-left:1px solid var(--rule);border-right:1px solid var(--rule)}.top{margin-top:16px;padding:0 32px;border-top:1px solid var(--rule)}main{padding:32px 32px 64px}}65.card{background-color:var(--card);border:1px solid var(--rule);border-radius:2px;padding:28px 24px}65.shell{max-width:28rem;margin:0 auto;padding:28px 16px 48px}66.top{display:flex;justify-content:center;margin:0 0 28px}67.wordmark{font-size:1.1875rem;line-height:1.6rem;font-weight:600;letter-spacing:-.02em;color:var(--ink);text-decoration:none}68.card{background-color:var(--card);border:1px solid var(--rule);border-radius:2px;padding:32px}69.card>:last-child{margin-bottom:0}70@media (max-width:39.99em){.card{background-color:transparent;border-color:transparent;padding:0}}71@media (min-width:40em){.shell{padding:12vh 24px 64px}}72main.document{max-width:44rem;margin:0 auto;padding:48px 16px 64px}67h1{font-size:1.5rem;line-height:2rem;font-weight:600;letter-spacing:-.015em;margin:0 0 20px;text-wrap:balance;overflow-wrap:anywhere}73h1{font-size:1.5rem;line-height:2rem;font-weight:600;letter-spacing:-.015em;margin:0 0 24px;text-wrap:balance;overflow-wrap:anywhere}74h2{font-size:1.1875rem;line-height:1.6rem;font-weight:600;letter-spacing:-.01em;margin:40px 0 12px}75p{margin:0 0 16px}76a{color:var(--ink);text-decoration-color:var(--input);text-decoration-thickness:1px;text-underline-offset:.2em}77a:hover{text-decoration-color:currentColor}78:focus-visible{outline:2px solid var(--primary);outline-offset:2px}79strong{font-weight:600}74.consent{border-top:1px solid var(--rule);border-bottom:1px solid var(--rule);padding:16px 0;margin:0 0 24px;overflow-wrap:anywhere}75.consent p{margin:0}76.consent p+p{margin-top:4px}80.small{font-size:.875rem;line-height:1.3rem}81.lead{margin:-16px 0 24px}82.consent{margin:-8px 0 24px;font-size:.875rem;line-height:1.3rem;padding:0 0 20px;border-bottom:1px solid var(--rule);overflow-wrap:anywhere}83.consent p{margin:0 0 4px}84.consent .warning{margin-top:12px}78.consent .may{margin:4px 0 12px}79.consent .may li{margin:0 0 4px}85details{margin-top:12px}86summary{cursor:pointer;font-weight:500}87details ul{margin:8px 0 0}88details li{margin:0 0 4px}89.warn{color:var(--waiting);font-weight:600;white-space:nowrap}90.warn svg{width:16px;height:16px;vertical-align:-2px;margin-right:6px}82.error{color:var(--refused);font-weight:600;overflow-wrap:anywhere}91.error{color:var(--refused);font-weight:500;font-size:.875rem;line-height:1.3rem;overflow-wrap:anywhere}92.muted{color:var(--muted)}84form{margin:0 0 24px}93form{margin:0}94label{display:block;margin:0 0 16px;font-size:.875rem;line-height:1.3rem;font-weight:500}95.field{margin:0 0 16px}96.field-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px}97.field-head label{margin:0}98.field-head a{font-size:.875rem;line-height:1.3rem;font-weight:400;color:var(--muted);text-decoration:none}99.field-head a:hover{color:var(--ink);text-decoration:underline}100input{display:block;width:100%;height:44px;margin-top:6px;padding:0 12px;font-family:inherit;font-size:16px;font-weight:400;color:var(--ink);background-color:var(--paper);border:1px solid;border-color:var(--input);border-radius:2px}87button,.button{display:inline-flex;align-items:center;justify-content:center;min-height:44px;padding:0 16px;font-family:inherit;font-size:1rem;font-weight:500;text-decoration:none;border:1px solid;border-radius:2px;cursor:pointer}101button,.button{display:flex;width:100%;align-items:center;justify-content:center;gap:10px;min-height:44px;padding:0 16px;font-family:inherit;font-size:1rem;font-weight:500;line-height:1.25rem;text-decoration:none;border:1px solid;border-radius:2px;cursor:pointer}102button{color:var(--on-primary);background-color:var(--primary);border-color:var(--primary)}89button.secondary,.button{color:var(--ink);background-color:var(--card);border-color:var(--input)}90button:hover{opacity:.88}91button.secondary:hover,.button:hover{background-color:var(--surface);opacity:1}92.button{display:flex;width:100%}93.actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:24px}103.button{color:var(--ink);background-color:var(--card);border-color:var(--input)}104button:hover{opacity:.9}105.button:hover{background-color:var(--surface)}106.button svg{flex:none;width:18px;height:18px}107button.link{display:block;width:auto;min-height:0;margin:16px auto 0;padding:2px 4px;color:var(--muted);background-color:transparent;border:0;font-size:.875rem;line-height:1.3rem;font-weight:400;text-decoration:none;text-underline-offset:.2em}108button.link:hover{color:var(--ink);opacity:1;text-decoration:underline}109.submit{margin-top:24px}110.or{display:flex;align-items:center;gap:12px;margin:20px 0}111.or .line{flex:1;height:1px;background-color:var(--rule)}112.aside{margin:24px 0 0;text-align:center}113pre{margin:8px 0 12px;padding:8px 12px;overflow-x:auto;background-color:var(--surface);border:1px solid var(--rule)}114code{font-family:"IBM Plex Mono",ui-monospace,"SF Mono",Menlo,Consolas,monospace;font-size:.8125rem;overflow-wrap:anywhere}115ul{margin:0;padding-left:1.25rem}116li{margin:0 0 8px}117`;118119type Width = "form" | "document";120102// A form is the focus shell: the wordmark as text in a bar between the rails,103// one card under it, and no navigation. A document (the platform's `/`)104// reads as plain prose.105const frame = (body: string, width: Width) =>121interface Frame {122 // The web's home, which the wordmark links to.123 readonly home?: string | undefined;124 // What leads elsewhere, under the card.125 readonly after?: string;126}127128// A form is the focus card: the wordmark over it, a line under it, and no129// navigation. A document (the platform's `/`) reads as plain prose.130const framed = (body: string, width: Width, frame: Frame) =>131 width === "document"132 ? `<main class="document">133${body}134</main>`110 : `<div class="frame"><header class="top"><p class="wordmark">${escapeHtml(Brand.name)}</p></header>111<main><div class="card">135 : `<div class="shell"><header class="top"><a class="wordmark" href="${escapeHtml(frame.home ?? "/")}">${escapeHtml(Brand.name)}</a></header>136<main class="card">137${body}113</div></main></div>`;138</main>${frame.after === undefined ? "" : `\n<p class="aside small muted">${frame.after}</p>`}</div>`;139115// `body` is HTML already escaped.116export const page = (title: string, body: string, width: Width = "form") =>140// `body` and `frame.after` are HTML already escaped.141export const page = (142 title: string,143 body: string,144 width: Width = "form",145 frame: Frame = {}146) =>147 `<!doctype html>148<html lang="en">149<head>150<meta charset="utf-8">
1 unmodified line
152<meta name="color-scheme" content="light dark">153<title>${escapeHtml(title)} · ${escapeHtml(Brand.name)}</title>154<style>${STYLE}</style>155</head>126<body>${frame(body, width)}</body>156<body>${framed(body, width, frame)}</body>157</html>158`;159160const WARNING_MARK = `<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M8 1.75 14.75 14H1.25z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><path d="M8 6.25v3.5M8 11.75v.25" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>`;161162// Google's "G", in its own colours, as its sign-in buttons show it.163const GOOGLE_MARK = `<svg viewBox="0 0 18 18" aria-hidden="true" focusable="false"><path fill="#4285F4" d="M17.64 9.2c0-.64-.06-1.25-.16-1.84H9v3.48h4.84a4.14 4.14 0 0 1-1.8 2.72v2.26h2.92c1.7-1.57 2.68-3.88 2.68-6.62z"/><path fill="#34A853" d="M9 18c2.43 0 4.47-.8 5.96-2.18l-2.92-2.26c-.8.54-1.84.86-3.04.86-2.34 0-4.32-1.58-5.03-3.7H.96v2.33A9 9 0 0 0 9 18z"/><path fill="#FBBC05" d="M3.97 10.72A5.41 5.41 0 0 1 3.68 9c0-.6.1-1.18.29-1.72V4.95H.96A9 9 0 0 0 0 9c0 1.45.35 2.83.96 4.05l3.01-2.33z"/><path fill="#EA4335" d="M9 3.58c1.32 0 2.5.45 3.44 1.35l2.58-2.58A8.65 8.65 0 0 0 9 0 9 9 0 0 0 .96 4.95l3.01 2.33C4.68 5.16 6.66 3.58 9 3.58z"/></svg>`;164165// What a grant lets a client do: it acts as the person, through the CLI's166// contracts, MCP and the git gateway alike.134const MAY = `<p>As you, it may:</p>167const MAY = `<details>168<summary>What it can do</summary>169<ul class="may">170<li>Read what you can read: projects, asks, code, verdicts, and any layer whose audience you are in</li>171<li>Claim, release and answer asks, and push to your forks</li>172<li>Make projects, and propose and flag asks</li>173<li>Open asks, take decisions, finish answers, land changes, vouch for or denounce people, and set write-only values where you are a maintainer; nobody can read a value back</li>174</ul>141<p>It never sees your password.</p>`;175<p>It never sees your password.</p>176</details>`;177178type Says = "who" | "who and what";179180/**181 * Who asks, said only of a client that is not ours: the web says nothing, and182 * the CLI one line, since the person started it themselves a moment ago.183 */184const askerParagraphs = (asker: Asker, says: Says = "who") => {185 if (asker.firstParty === "web") {186 return "";187 }188189 if (asker.firstParty === "cli") {190 return `<p class="lead small muted">This finishes signing in the CLI on this computer. Continue only if you just ran <code>${escapeHtml(Brand.cli)} login</code>.</p>`;191 }192193 const name = `<strong>${escapeHtml(asker.clientName)}</strong>`;194195 const domain =196 asker.clientDomain === undefined197 ? ""151 : ` (published by ${escapeHtml(asker.clientDomain)})`;198 : ` (${escapeHtml(asker.clientDomain)})`;199200 const loopback = asker.redirectIsLoopback201 ? `<p class="warning"><strong class="warn">${WARNING_MARK}Warning</strong> This sends access to an app on your computer. Continue only if you just started signing in from it.</p>`202 : "";203204 const label = says === "who" ? "Who asks" : "Who asks and what it may do";205206 return `<section class="consent" aria-label="${label}">160<p>${name}${domain} asks to act as you.</p>207<p>${name}${domain} wants to act as you.</p>208<p>Access goes to <strong>${escapeHtml(asker.redirectHost)}</strong>.</p>209${loopback}210${says === "who and what" ? MAY : ""}211</section>`;212};213214const homeOf = (asker: Asker): Frame => ({ home: asker.home });215216const messageParagraph = (message?: string) =>217 message === undefined218 ? ""219 : `<p class="error" role="alert">${escapeHtml(message)}</p>`;
1 unmodified line
221const hiddenFields = (form: PendingForm) =>222 `<input type="hidden" name="request" value="${escapeHtml(form.request)}">223<input type="hidden" name="csrf" value="${escapeHtml(form.csrf)}">`;224225const OR = `<div class="or small muted"><span class="line" aria-hidden="true"></span>or<span class="line" aria-hidden="true"></span></div>`;226227// A link, so no form posts to Google.177const googleChoices = (offers: Offers, form: PendingForm) =>228const googleStart = (offers: Offers, form: PendingForm) =>229 offers.google179 ? {180 link: `<button type="submit" class="secondary" formaction="${GOOGLE_PATHS.link}">Sign in and link Google</button>`,181 start: `<p><a href="${GOOGLE_PATHS.start}?request=${encodeURIComponent(form.request)}" class="button">Continue with Google</a></p>182<p class="muted">Or sign in with your email or handle and password.</p>`,183 }184 : { link: "", start: "" };230 ? `<a href="${GOOGLE_PATHS.start}?request=${encodeURIComponent(form.request)}" class="button">${GOOGLE_MARK}Continue with Google</a>231${OR}`232 : "";233234const LINK_GOOGLE = "Sign in and link your Google account";235236const valueOf = (value?: string) =>237 value === undefined ? "" : ` value="${escapeHtml(value)}"`;238239const withRequest = (path: string, form: PendingForm) =>
3 unmodified lines
243 asker: Asker,244 form: PendingForm,245 offers: Offers,246 message?: string197) => {198 const google = googleChoices(offers, form);199200 return page(247) =>248 page(249 "Sign in",202 `<h1>Sign in</h1>250 `<h1>Sign in to ${escapeHtml(Brand.name)}</h1>251${askerParagraphs(asker, "who and what")}204${google.start}252${googleStart(offers, form)}253${messageParagraph(message)}254<form method="post" action="/authorize">255${hiddenFields(form)}256<label>Email or handle <input name="login" autocomplete="username" autocapitalize="none" spellcheck="false" required></label>209<label>Password <input type="password" name="password" autocomplete="current-password" required></label>210<div class="actions">211<button type="submit">Sign in</button>212${google.link}257<div class="field">258<div class="field-head"><label for="password">Password</label><a href="${withRequest(ACCOUNT_PATHS.reset, form)}">Forgot password?</a></div>259<input type="password" name="password" id="password" autocomplete="current-password" required>260</div>214</form>215<p><a href="${withRequest(ACCOUNT_PATHS.reset, form)}">Forgot your password?</a></p>216<p>New here? <a href="${withRequest("/signup", form)}">Sign up</a>.</p>`261<div class="submit"><button type="submit">Sign in</button></div>262${offers.google ? `<button type="submit" class="link" formaction="${GOOGLE_PATHS.link}">${LINK_GOOGLE}</button>` : ""}263</form>`,264 "form",265 {266 ...homeOf(asker),267 after: `New here? <a href="${withRequest("/signup", form)}">Create an account</a>`,268 }269 );218};270271export interface ProfileValues {272 readonly displayName?: string;273 readonly handle?: string;
15 unmodified lines
289 page(290 "Set up your profile",291 `<h1>Set up your profile</h1>292${askerParagraphs(asker)}242<p>Google confirmed who you are. This Google account has not signed in here before: choose the handle and name people will know you by.</p>293<p>Google confirmed who you are. Choose the handle and name people will know you by.</p>294${messageParagraph(message)}295<form method="post" action="${GOOGLE_PATHS.handle}">296${hiddenFields(form)}297${DISPLAY_NAME_FIELD(values.displayName)}298${HANDLE_FIELD(values.handle)}248<div class="actions"><button type="submit">Sign up</button></div>249</form>250<p>Have an account with a password? <a href="${escapeHtml(signInHref)}">Sign in with it</a> and choose "Sign in and link Google".</p>`299<div class="submit"><button type="submit">Create account</button></div>300</form>`,301 "form",302 {303 ...homeOf(asker),304 after: `Have an account with a password? <a href="${escapeHtml(signInHref)}">Sign in with it</a>, then choose "${LINK_GOOGLE}".`,305 }306 );307308export interface SignUpValues extends ProfileValues {309 readonly email?: string;
1 unmodified line
311312export const signUpPage = (313 asker: Asker,314 form: PendingForm,315 offers: Offers,316 signInHref: string,317 values: SignUpValues,318 message?: string319) =>320 page(265 "Sign up",266 `<h1>Sign up</h1>321 "Create your account",322 `<h1>Create your account</h1>323${askerParagraphs(asker, "who and what")}324${googleStart(offers, form)}325${messageParagraph(message)}326<form method="post" action="/signup">327${hiddenFields(form)}328<label>Email <input type="email" name="email" autocomplete="email" autocapitalize="none" spellcheck="false" maxlength="254" required${valueOf(values.email)}></label>329${DISPLAY_NAME_FIELD(values.displayName)}330${HANDLE_FIELD(values.handle)}331<label>Password, 12 to 256 characters <input type="password" name="password" autocomplete="new-password" minlength="12" maxlength="256" required></label>275<div class="actions"><button type="submit">Sign up</button></div>332<div class="submit"><button type="submit">Create account</button></div>333</form>277<p>We mail a code to the address, to check it is yours.</p>278<p>Have an account? <a href="${escapeHtml(signInHref)}">Sign in</a>.</p>`334<p class="small muted aside">We mail a code to the address, to check it is yours.</p>`,335 "form",336 {337 ...homeOf(asker),338 after: `Have an account? <a href="${escapeHtml(signInHref)}">Sign in</a>`,339 }340 );341342export interface CodeForm {343 readonly action: string;
11 unmodified lines
355 message?: string356) =>357 page(358 "Enter the code",298 `<h1>Enter the code we mailed you</h1>359 `<h1>Check your email</h1>360${askerParagraphs(asker)}361<p>${escapeHtml(code.intro)} It works for 10 minutes.</p>362${messageParagraph(message)}363<form method="post" action="${code.action}">364${hiddenFields(form)}365<label>Code <input name="code" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9 -]*" maxlength="12" required></label>366${code.newPassword ? `<label>New password, 12 to 256 characters <input type="password" name="password" autocomplete="new-password" minlength="12" maxlength="256" required></label>` : ""}306<div class="actions"><button type="submit">Continue</button></div>307</form>308<p>No mail? Check your spam folder, or <a href="${escapeHtml(code.startOverHref)}">start again</a>.</p>`367<div class="submit"><button type="submit">Continue</button></div>368</form>`,369 "form",370 {371 ...homeOf(asker),372 after: `No mail? Check your spam folder, or <a href="${escapeHtml(code.startOverHref)}">start again</a>.`,373 }374 );375376export const addEmailPage = (377 asker: Asker,
10 unmodified lines
388${messageParagraph(message)}389<form method="post" action="${ACCOUNT_PATHS.addEmail}">390${hiddenFields(form)}391<label>Email <input type="email" name="email" autocomplete="email" autocapitalize="none" spellcheck="false" maxlength="254" required${valueOf(value)}></label>327<div class="actions"><button type="submit">Send the code</button></div>328</form>329<p><a href="${escapeHtml(startOverHref)}">Sign in as someone else</a></p>`392<div class="submit"><button type="submit">Send the code</button></div>393</form>`,394 "form",395 {396 ...homeOf(asker),397 after: `<a href="${escapeHtml(startOverHref)}">Sign in as someone else</a>`,398 }399 );400401export const resetPage = (402 asker: Asker,
10 unmodified lines
413${messageParagraph(message)}414<form method="post" action="${ACCOUNT_PATHS.reset}">415${hiddenFields(form)}416<label>Email <input type="email" name="email" autocomplete="email" autocapitalize="none" spellcheck="false" maxlength="254" required${valueOf(value)}></label>348<div class="actions"><button type="submit">Send the code</button></div>349</form>350<p>Remembered it? <a href="${escapeHtml(signInHref)}">Sign in</a>.</p>`417<div class="submit"><button type="submit">Send the code</button></div>418</form>`,419 "form",420 {421 ...homeOf(asker),422 after: `Remembered it? <a href="${escapeHtml(signInHref)}">Sign in</a>`,423 }424 );425353export const problemPage = (message: string) =>426export const problemPage = (message: string, home = "/") =>427 page(428 "Sign-in problem",429 `<h1>Signing in did not work</h1>430<p role="alert">${escapeHtml(message)}</p>358<p><a href="/">What this host serves</a></p>`431<p><a href="${escapeHtml(home)}">Back to ${escapeHtml(Brand.name)}</a></p>`,432 "form",433 { home }434 );
modified:apps/platform/src/auth/provider.ts+5 added
modified:apps/platform/src/auth/sign-in.ts+38 added-7 removed
30 unmodified lines
31import { SignInAttempts } from "./attempts.ts";32import { CLI_CLIENT_PATH, cliClientMetadata } from "./cli-client.ts";33import { codeMatches, codeTag, deadTag, freshCode } from "./codes.ts";34import type { CodePurpose } from "./codes.ts";35import { firstPartyOf } from "./first-party.ts";36import { Mailer } from "./mailer.ts";37import { OAuthStore } from "./oauth-store.ts";38import {39 ACCOUNT_PATHS,
34 unmodified lines
74 SignInOffers,75 { readonly google: Option.Option<string> }76>()("platform/SignInOffers") {}7778// The web's address, when the platform knows it: the wordmark links there, and its client is told apart from any other.79export class SignInHome extends Context.Service<80 SignInHome,81 { readonly webUrl: Option.Option<string> }82>()("platform/SignInHome") {}8384// Nobody signs up as a handle a named session holds, or an account would call as that person.85export class HeldHandles extends Context.Service<86 HeldHandles,87 { readonly handles: readonly Handle[] }
198 unmodified lines
286287export const askerOf = (request: AuthRequest) =>288 Effect.gen(function* () {289 const api = yield* oauthApi;290 const { origin } = yield* Authorization;291 const { webUrl } = yield* SignInHome;292293 const consent = yield* provider(() =>294 api.describeConsent(forProvider(request))295 );296297 const asker: Asker = {298 clientDomain: consent.clientDomain,299 clientName: consent.clientName,300 firstParty: firstPartyOf(request.clientId, origin, webUrl),301 home: Option.getOrElse(webUrl, () => "/"),302 redirectHost: consent.redirectHost,303 redirectIsLoopback: consent.redirectIsLoopback,304 };305
548 unmodified lines
854855 const pending = yield* openState(cookieKey, sealed);856857 const asker = yield* askerOf(pending.request);858 const { google } = yield* SignInOffers;859860 return htmlPage(861 signUpPage(862 asker,863 { csrf: pending.csrf, request: sealed },864 { google: Option.isSome(google) },865 authorizeHref(pending.request),866 {}867 ),868 200,
76 unmodified lines
945 values: SignUpValues,946 status: number,947 message: string948) =>936 Effect.map(askerOf(request), (asker) =>937 htmlPage(938 signUpPage(asker, form, authorizeHref(request), values, message),949 Effect.gen(function* () {950 const asker = yield* askerOf(request);951 const { google } = yield* SignInOffers;952953 return htmlPage(954 signUpPage(955 asker,956 form,957 { google: Option.isSome(google) },958 authorizeHref(request),959 values,960 message961 ),962 status,963 request.redirectUri941 )942 );964 );965 });966967const signUpCode = (request: AuthRequest, email: Email): CodeForm => ({968 action: ACCOUNT_PATHS.signUpVerify,969 intro: codeSentTo(email),
349 unmodified lines
1319 return HttpServerResponse.fromWeb(response);1320 });13211322export const failedPage = (failed: SignInFailed) =>1300 Effect.succeed(1323 Effect.map(Effect.service(SignInHome), ({ webUrl }) =>1324 failed.redirectTo === undefined1302 ? htmlPage(problemPage(failed.reason), 400)1325 ? htmlPage(1326 problemPage(1327 failed.reason,1328 Option.getOrElse(webUrl, () => "/")1329 ),1330 4001331 )1332 : HttpServerResponse.redirect(failed.redirectTo, {1333 headers: { "cache-control": "no-store" },1334 status: 302,1335 })
4 unmodified lines
1340 | HeldHandles1341 | Mailer1342 | OAuthStore1343 | SignInAttempts1344 | SignInHome1345 | SignInKeys1346 | SignInOffers;13471348export const signInRoutes = HttpRouter.use((router) =>
2 unmodified lines
1351 Context.add(HeldHandles, yield* HeldHandles),1352 Context.add(Mailer, yield* Mailer),1353 Context.add(OAuthStore, yield* OAuthStore),1354 Context.add(SignInAttempts, yield* SignInAttempts),1355 Context.add(SignInHome, yield* SignInHome),1356 Context.add(SignInKeys, yield* SignInKeys),1357 Context.add(SignInOffers, yield* SignInOffers)1358 );1359
31 unmodified lines
added:apps/platform/test/first-party.test.ts+40 added
modified:apps/platform/test/google.test.ts+1 added-1 removed
600 unmodified lines
601});602603describe("Google sign-in, with a Google OAuth client", () => {604 it.live(605 'offers "Continue with Google" and "Sign in and link Google" on the sign-in page',605 'offers "Continue with Google" and "Sign in and link your Google account" on the sign-in page',606 () =>607 Effect.gen(function* () {608 const world = yield* googleWorld();609
713 unmodified lines
modified:apps/platform/test/oauth.test.ts+37 added-1 removed
529 unmodified lines
530 "text/html; charset=utf-8",531 `${CSP} http://127.0.0.1:${port}`,532 "DENY",533 ]);534 expect(page.html).toContain(`${Brand.name} CLI`);534 expect(page.html).toContain(535 "This finishes signing in the CLI on this computer."536 );537 expect(page.html).not.toContain("What it can do");538 expect(page.html).not.toMatch(/<script|<link|<img|src=|url\(|@import/u);539 expect(Option.isSome(formOf(page.response, page.html))).toBeTruthy();540 })541 );542543 it.live(544 "asks a client from another address for consent, though it names itself as the platform's CLI",545 () =>546 Effect.gen(function* () {547 const world = yield* signInWorld();548 const url = authorizeUrl();549550 // The same metadata document, served at another origin: its name is ours, its id is not.551 url.searchParams.set("client_id", "https://other.test/oauth/cli");552553 const page = yield* world554 .fetch(new Request(url))555 .pipe(Effect.flatMap(read));556557 expect({558 asks: new RegExp(559 `<strong>${Brand.name} CLI</strong>[^<]* wants to act as you\\.`,560 "u"561 ).test(page.html),562 lists: page.html.includes("<summary>What it can do</summary>"),563 ours: page.html.includes("This finishes signing in the CLI"),564 status: page.response.status,565 warns: page.html.includes("Warning</strong>"),566 }).toStrictEqual({567 asks: true,568 lists: true,569 ours: false,570 status: 200,571 warns: true,572 });573 })574 );575576 it.live(577 "lets the code go back to an IPv6 loopback, which no CSP host can name",578 () =>579 Effect.gen(function* () {580 const world = yield* signInWorld();
940 unmodified lines
modified:apps/platform/test/pages.test.ts+109 added-8 removed
31 unmodified lines
32 redirectHost: "127.0.0.1:53682",33 redirectIsLoopback: true,34};3536const ourWeb: Asker = {37 clientName: `${Brand.name} web`,38 firstParty: "web",39 home: "https://web.example",40 redirectHost: "web.example",41 redirectIsLoopback: false,42};4344const ourCli: Asker = {45 clientName: `${Brand.name} CLI`,46 firstParty: "cli",47 redirectHost: "127.0.0.1:53682",48 redirectIsLoopback: true,49};5051const form: PendingForm = { csrf: "csrf-token", request: "sealed-request" };5253const home = Effect.gen(function* () {54 const response = yield* homeResponse(
81 unmodified lines
136 ),137 "sign-up": signUpPage(138 local,139 form,140 { google: true },141 "/authorize?x=1",142 { displayName: "Alice", email: "alice@mail.example", handle: "alice" },143 "A password is 12 to 256 characters."144 ),
290 unmodified lines
435436const EDGES = /^(?:border-(?:top|right|bottom|left)|box-shadow|outline)/u;437438describe.each(SIGN_IN_PAGES)("$name, in the focus look", ({ html }) => {423 it("shows the wordmark as text, then one card, and no navigation", () => {424 const wordmark = html.indexOf(`<p class="wordmark">${Brand.name}</p>`);439 it("shows the wordmark as a link home, then one card, and no navigation", () => {440 const wordmark = html.indexOf(441 `<a class="wordmark" href="/">${Brand.name}</a>`442 );443444 const card = html.indexOf('class="card"');445446 expect(wordmark).toBeGreaterThan(html.indexOf("<body"));447 expect(card).toBeGreaterThan(wordmark);
67 unmodified lines
515 it("names the client and lists what it may do as you", () => {516 const consent = consentOf(PAGES["sign-in"]);517518 expect(consent).toContain(500 "<strong>Claude</strong> (published by claude.ai)"519 "<strong>Claude</strong> (claude.ai) wants to act as you."520 );521 expect(consent.match(/<li>/gu)).toHaveLength(4);522 expect(consent).toContain("<li>Claim, release and answer asks");523 expect(consent).toContain("It never sees your password.");
1 unmodified line
525 "finish answers, land changes, vouch for or denounce people"526 );527 });528529 it("keeps what the client may do behind a disclosure, the who and where in view", () => {530 expect(consentOf(PAGES["sign-in"])).toMatch(531 /wants to act as you\.<\/p>\s*<p>Access goes to <strong>claude\.ai<\/strong>\.<\/p>[\s\S]*<details>\s*<summary>What it can do<\/summary>\s*<ul class="may">/u532 );533 });534535 it("lists the same on the sign-up page, where a newcomer allows it", () => {536 expect(mayListOf(PAGES["sign-up"])).toBeDefined();537 expect(mayListOf(PAGES["sign-up"])).toBe(mayListOf(PAGES["sign-in"]));538 });
17 unmodified lines
556 redirectIsLoopback: true,557 };558559 const named = [535 signUpPage(hostile, form, "/authorize", {}),560 signUpPage(hostile, form, { google: true }, "/authorize", {}),561 profilePage(hostile, form, "/authorize", {}),562 addEmailPage(hostile, form, "/authorize"),563 resetPage(hostile, form, "/authorize"),564 codePage(hostile, form, {
13 unmodified lines
578 });579580 it("says who asks and where access goes before Google and the form", () => {581 const html = PAGES["sign-in"];557 const asks = html.indexOf("asks to act as you");582 const asks = html.indexOf("wants to act as you");583 const goes = html.indexOf("Access goes to");584 const google = html.indexOf("Continue with Google");585 const formAt = html.indexOf("<form");586
41 unmodified lines
628 expect(PAGES["sign-in"]).toMatch(629 /<p class="error" role="alert">The email, handle or password is wrong\.<\/p>/u630 );631 expect(PAGES["the problem page"]).not.toContain('class="error"');607 expect(PAGES["the problem page"]).toMatch(/<a href="\/">/u);632 expect(PAGES["the problem page"]).toMatch(633 new RegExp(`<a href="/">Back to ${Brand.name}</a>`, "u")634 );635 });636});637638describe("the sign-in page, for one of the platform's own clients", () => {639 it("asks the web's reader nothing about consent", () => {640 const html = signInPage(ourWeb, form, { google: true });641642 expect(consentOf(html)).toBe("");643 expect(html).not.toContain("What it can do");644 expect(html).not.toContain("act as you");645 expect(html).toContain(`<h1>Sign in to ${Brand.name}</h1>`);646 });647648 it("tells the CLI's reader in one line what finishing does, with no warning or list", () => {649 const html = signInPage(ourCli, form, { google: true });650651 expect(consentOf(html)).toBe("");652 expect(html).toContain(653 `This finishes signing in the CLI on this computer. Continue only if you just ran <code>${Brand.cli} login</code>.`654 );655 expect(html).not.toContain("Warning");656 expect(html).not.toContain("What it can do");657 });658659 it("links the wordmark and the problem page to the web's home when it is known", () => {660 expect(signInPage(ourWeb, form, { google: false })).toContain(661 `<a class="wordmark" href="https://web.example">${Brand.name}</a>`662 );663 expect(problemPage("Expired.", "https://web.example")).toContain(664 `<a href="https://web.example">Back to ${Brand.name}</a>`665 );666 });667668 it("treats every page's asker the same way", () => {669 const pages = [670 signUpPage(ourWeb, form, { google: false }, "/authorize", {}),671 profilePage(ourWeb, form, "/authorize", {}),672 addEmailPage(ourWeb, form, "/authorize"),673 resetPage(ourWeb, form, "/authorize"),674 ];675676 for (const html of pages) {677 expect(consentOf(html)).toBe("");678 expect(html).not.toContain("act as you");679 }680 });681});682683describe("a sign-in form shown again", () => {684 it("escapes every value the person typed", () => {685 const typed = `"><script>alert(1)</script>`;686687 const pages = [616 signUpPage(local, form, "/authorize", {688 signUpPage(local, form, { google: false }, "/authorize", {689 displayName: typed,690 email: typed,691 handle: typed,692 }),
14 unmodified lines
707 });708709 it("never fills in a password", () => {710 expect(639 signUpPage(local, form, "/authorize", { email: "alice@mail.example" })711 signUpPage(local, form, { google: false }, "/authorize", {712 email: "alice@mail.example",713 })714 ).toMatch(/<input type="password" name="password" [^>]*required>/u);715 });716});717
6 unmodified lines
724 );725 expect(html).toContain('href="/signup?request=sealed-request"');726 expect(html).toContain("Email or handle");727 });728729 it("offers Google first, then the password, with linking Google as a quiet choice under Sign in", () => {730 const html = signInPage(claude, form, { google: true });731 const google = html.indexOf("Continue with Google");732 const or = html.indexOf('class="or');733 const formAt = html.indexOf("<form");734 const signIn = html.indexOf('<button type="submit">Sign in</button>');735736 const link = html.indexOf(737 '<button type="submit" class="link" formaction="/oauth/google/link">Sign in and link your Google account</button>'738 );739740 expect(or).toBeGreaterThan(google);741 expect(formAt).toBeGreaterThan(or);742 expect(signIn).toBeGreaterThan(formAt);743 expect(link).toBeGreaterThan(signIn);744 expect(signInPage(claude, form, { google: false })).not.toMatch(745 /Continue with Google|formaction=/u746 );747 });748749 it("offers Google on the sign-up page too, when the platform has it", () => {750 expect(PAGES["sign-up"]).toContain("Continue with Google");751 expect(752 signUpPage(local, form, { google: false }, "/authorize", {})753 ).not.toContain("Continue with Google");754 });755});
modified:DESIGN.md+1 added-1 removed
402 unmodified lines
403| `focus` | sign-in, MCP consent, new project, new proposal | a centred, ruled card, `--container-focus` (400 px) | the wordmark only, in the framed bar | none |404405A shell sets its gutter once, on its frame, and every bar and page inside it reads it: 16 px on a phone, 20 px from `tablet`, and from `shell` (1120 px) `--gutter-site` in the site, the docs and a focused page, or `--gutter-project` in a project.406407**Rails.** The site, the docs and a focused page are ruled: from `tablet`, the container stands `--frame-inset` (24 px) in from the viewport and carries a hairline down each edge, the page's full height (`RAILS` in `app-shell.tsx`), and the top bar is a box between them, `--frame-gap` (16 px) under the viewport's top, with a hairline over and under it. Everything inside (the frame, a section's rule, the footer's rule) runs rail to rail, and the gutter sits inside the rails, so content stands 32 px in from them. Below `tablet` the rails and the gap go: the bar keeps its rule underneath, and the page takes the phone's 16 px gutter. The top bar's height stays `--top-bar`, borders included, so what sticks under it reads `--stick-bar` unchanged, and when the bar sticks it sits flush at the top. The platform's own pages draw the same frame at the card's width, in their inline style. A project has no rails.407**Rails.** The site, the docs and a focused page are ruled: from `tablet`, the container stands `--frame-inset` (24 px) in from the viewport and carries a hairline down each edge, the page's full height (`RAILS` in `app-shell.tsx`), and the top bar is a box between them, `--frame-gap` (16 px) under the viewport's top, with a hairline over and under it. Everything inside (the frame, a section's rule, the footer's rule) runs rail to rail, and the gutter sits inside the rails, so content stands 32 px in from them. Below `tablet` the rails and the gap go: the bar keeps its rule underneath, and the page takes the phone's 16 px gutter. The top bar's height stays `--top-bar`, borders included, so what sticks under it reads `--stick-bar` unchanged, and when the bar sticks it sits flush at the top. The platform's sign-in pages are not ruled: at the card's width, rails and a boxed bar read as boxes in boxes, so they draw one centred column, the wordmark (linking the web's home) over the card and what leads elsewhere under it, the card a bordered surface from `tablet` and the page itself on a phone. The platform's own clients (the web and the CLI, told by their client ids) are asked no consent there; any other client's name, address and grant are said above the form, the grant behind a disclosure. A project has no rails.408409From `columns` (1100 px, `--breakpoint-columns`) a side column stands beside its main column; below it, every side column stacks under its main column. From `nav` (900 px, `--breakpoint-nav`) the top bar shows its links; below it they fold into a menu. Phone width (360 px) is a first-class layout: nothing scrolls sideways.410411**The four rules (ADR 0041):**
229 unmodified lines