oficina / home Public

feat/oficina-id-native-connect

🤖 Oficina ID native slice A — the consumer (connect) half. Implements Home spec docs/superpowers/specs/2026-11-14-oficina-id-native.md (approved by Paul and cleared to build, 2026-11-14) §7, §8 and the matching §13 gates, in handoff and connect. Docs is wired to it on oficina/docs branch feat/oficina-id-native-connect. The Home id.* side (grant, codes, passkeys, assert) is a separate branch by another agent; the two meet only at the wire formats below. Do not merge without review. No deploy.

What changed

  • handoff (native.go): NativeChallenge/NativeNonce, the one derivation both assert and the instance use, with a fixed test vector; Store.Verify (consumes nothing); Store.Reserve (burns (iss,jti) in its own committed transaction, refuses a jti already reserved or waiting in a browser inbox).
  • connect: one predicate. IsHomeDerived (home-assertion, home-assertion-native, home-native-web) replaces the literal checks (finish's CurrentSubject, existingPerson, signedIn). Expired refuses native and native-web sessions 7 days after At, absolute, or with no At.
  • connect: members choose (§8, browser). New Config.Admit, set with Unlinked and HomeOnly or not at all (New enforces it). The roster decision comes first and allocates nothing: a non-member gets today's unknown answer byte for byte, an unavailable roster 503, and a Member a sealed, single-use, browser-bound 10-minute choice proof (linkstore migration 0003_choice_proofs.sql) plus a 303 to /account/home/choose. ChoosePage/ChoosePost: the form token is an HMAC of the proof cookie and the POST needs an exact same-origin Origin. "connect" consumes the proof and resumes linking through /signin/local. "new" refuses while any app session is present, consumes the proof in its own transaction, rechecks the link and Admit with no transaction open, allocates through Unlinked, re-resolves and mints, then lands on /. Any app session at finish still gets unknown plus the marker, before Admit, with no proof issued.
  • connect: NativeExchange (§7). POST /native/oficina-id runs the spec's five steps in order and holds no transaction across any hook or the mint. It mints through the new Config.MintNativeSession, with method home-assertion-native. Routes.Middleware lets this one path past CSRF, because the exchange itself refuses Origin/Sec-Fetch-Site.
  • Sign-out also clears a pending choice; Sweep drops expired proofs. The README documents all of it.

Wire notes (please check; flagged items need a ruling or the other agents' agreement)

  1. Nonce derivation (aligned with the Swift client, a1039a1). verifier = 32 random bytes, sent as 43-char unpadded base64url. challenge = base64url(SHA-256(the verifier's 43 ASCII characters)), the S256 convention /native/exchange already uses; this is assert's challenge. nonce = base64url(SHA-256("oficina-id/native/v1" ‖ 0x00 ‖ the challenge's raw 32 bytes)[:16]), 22 chars. It is cut to 16 bytes because a rastrillo assertion nonce must be exactly 16 bytes. Vector: verifier AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8, challenge 6oZqdX5MOLq_qBJ8vppAnT4fk6AP8UiP9zX8-Rev_9A, nonce ZVVVj2zbBfhkAIwAOKNylg. *FLAG for the id. agent:** Home's assert should call handoff.NativeNonce (repin handoff in the root module) rather than reimplement it.
  2. Request: {"assertion","verifier","target"?,"choice"?}, Content-Type: application/json, at most 12 KiB, unknown or duplicate members refused. No Origin and no Sec-Fetch-Site. This differs from rastrillo/native's /native/exchange, which needs same-origin evidence to pass CSRF. No cookies are needed; the Swift client should send none.
  3. Answers are JSON {"state":…}, no-store, with no Set-Cookie: 200 ok {name, value, expires_at[, target]} (send name=value as the Cookie on instance requests, as with /native/exchange today); 403 unknown; 409 choose; 503 unavailable. Two additions (FLAG): 400 invalid for a malformed request and 401 failed for an assertion that is not accepted (bad, expired, wrong audience or verifier, or already used: fetch a fresh one and retry once). 404 when an instance has not enabled the exchange.
  4. target (FLAG: the spec names it but does not define it). I read it as an optional local path the app wants to open. It is validated with handoff.SafePath (400 otherwise), echoed in the 200, and has no other effect.
  5. Step 5's "recheck admission" (FLAG). Re-Resolve (whose LookupPerson rechecks a linked account's admission), plus Admit again for a Home-only person. A Home-only person the roster no longer lists therefore gets the identical 403 natively. The browser path does not ask the roster at mint, as before.
  6. The choose page's button order (FLAG for Paul). The spec lists "Connect my existing account" first; Docs draws it as the primary button and "I'm new here — continue with Oficina ID" as the ghost.
  7. Natively, "Connect my existing account" opens <origin>/account/home, as the spec says. choice is sent only from the "I'm new here" button.

Deferred / not here

  • Unlink: TODO for whoever builds it (Fable, 2026-11-14). Neither connect nor Docs has an unlink path today (Docs' triggers forbid deleting links). When one is built, unlinking a subject must delete every IsHomeDerived session for it (home-assertion, home-assertion-native, home-native-web) and that subject's home_choice_proofs rows, in the same change, with the "concurrent exchange, unlink and relink" gate from spec §13. Concurrent native choices for one subject are tested today (one person).
  • Known and accepted (Fable; recorded in the spec): an instance cannot tell a native assertion from a browser one minted through /authorize with a caller-chosen nonce equal to a native nonce. Only the subject's own browser can do that, for itself, so it grants no extra privilege. There is a comment at the nonce check in native.go.
  • home-native-web is only recognised (predicate and age limit); minting it is slice D.
  • Slice C (Sheets, Calendar, Memoria, Calls), no change yet. To adopt: set Admit (teammode AdmitUnlinked: ErrNotMember→connect.ErrNoPerson), MintNativeSession; mount ChoosePage/ChoosePost/NativeExchange; render state choose from ChoiceFor + English["choose_*"]; use IsHomeDerived/Expired. A team-mode app that bumps connect without setting Admit refuses to boot (intended: §8's invariant). A shared home-choose template could move into estilo homeconnect.
  • teammode's own go.mod still pins an older connect (unchanged; nothing there calls the new API).

Repin after landing

connect/go.mod requires handoff at branch commit d11246a; after the squash, repin it to the main commit. Docs' branch pins connect+handoff at this branch's tip and needs the same repin.

Wire alignment with the Swift client (rastrillo/native native/oficina-id-slice-a @a1039a1)

  • Challenge: I first hashed the verifier's raw bytes, then changed to hashing the string (d11246a), so the two now match.
  • The 200 answer is a superset of {name, value}: it also carries state and expires_at, which the client ignores. 403, 409 and 503 match. No Origin and no cookie on the request match. target is never sent, which is fine because it is optional.
  • 400 invalid and 401 failed are extra. The client should treat 401 from the exchange as "fetch a fresh assertion, retry once", not as a dead session.
  • /native/web/end is slice D. connect does not serve it yet.
  • The directory (https://oficina.works/native/oficina-id) needs its own NativeExchange-equivalent. The directory is Home's root module, not a connect consumer, so that belongs to the id.*/directory branch. handoff.Verify/Reserve/NativeNonce are there for it.

Review

Fable reviewed a4da657: APPROVE AFTER FIXES. The fixes are at c70205a:

  • The writer-held gate now fails fast with "called with the writer held: [Unlinked]". I proved it with Fable's mutation: holding a transaction across Unlinked used to hang the gate for more than 3 minutes, and now fails it in 2 s.
  • The gate also covers a known person's browser finish.
  • Sign-out deletes the pending choice-proof row as well as its cookie.
  • CurrentSubject ignores an Expired session.
  • MintNativeSession now states that the session store's lifetime must be at least 7 days. make test is green at c70205a.
Commits 0
Discussions 0 0 open
Tasks 5/7 done

Activity