Repository navigation
feat(api): sign in to Annex through auth.cubityfir.st and keep account data locally - #23
Merged
Merged
Conversation
Annex is becoming an OIDC client of auth.cubityfir.st. Migration 0065 adds the local users mirror, Annex's own sessions table, and the Annex-only tables that used to live in cubedocs-auth (user_billing, user_preferences, webhook_events, user_deletions, user_moderation_events, admin_audit_log), plus identity_deletions for the deletion sync. scripts/import-auth-data.mjs turns a cubedocs-auth export into INSERT OR IGNORE statements for cubedocs-main (one-time cutover copy).
Annex verifies its own sessions against cubedocs-main instead of the auth DB. New account/ module (shared with the admin worker later): HS256 session JWTs, sessions with a kind (app/admin) and a single-use handoff code, account standing from the IdentityService RPC cached ~60s with the users mirror as fallback, and an oauth4webapi-based OIDC client (PKCE S256, state, nonce, id_token claims and JWKS signature checks). Routes: GET /auth/login, GET /auth/callback, POST /auth/exchange, POST /auth/logout, and a localhost-only POST /dev/quick-login that mints mirror-only dev users. Issuer, client id/secret and redirect URIs come from OIDC_* vars and APP_ORIGIN.
Billing (Checkout, Customer Portal, Stripe webhook), the preference routes (ink prefs, fonts, theme, bio, handle, timezone), GET/PATCH /me and the profile card now run in the API worker against cubedocs-main. The frontend worker forwards /stripe/webhook to the API worker, so the URL in the Stripe dashboard is unchanged. Every AUTH_DB read and AUTH proxy is gone: invite-by-email asks the identity service (IdentityService.findUserByEmail) and mirrors the result; member plans, handles, reports, invite links, API-key owners and collab session re-checks read the users mirror; account standing comes from the identity service. Password, email, 2FA, passkey, session and account-deletion routes are removed (they live on auth.cubityfir.st), and PATCH /me refuses name changes. Server-side OIDC requests (discovery, JWKS, token) go through a new IDENTITY_OIDC service binding to cubityfirst-auth: a same-zone fetch() to auth.cubityfir.st would reach the origin, not the identity worker. Local dev falls back to the public issuer URL when the binding has no target.
* feat(frontend): sign in and out through auth.cubityfir.st
/login and /register hand off to /api/auth/login (the hosted page links to
registration and returns here); /auth/complete redeems the callback's
single-use code for the session JWT, which still lives in localStorage.
Sign-out revokes the Annex session and continues to the identity
service's end-session URL. Local dev keeps the quick-login buttons.
Removed the pages and helpers that moved to auth.cubityfir.st (login,
register, check/verify email, OAuth authorize, 2FA prompts, passkeys,
pending OAuth) and the security parts of account settings (password,
email change, TOTP, passkeys, sessions, delete account); settings now
links to the identity service's account and security pages, and email
and display name are read-only. /oauth/authorize redirects to the
identity service, query string included (frontend worker and SPA).
Dropped the now-unused zxcvbn, react-qr-code, @simplewebauthn/browser and
Turnstile script.
* chore(auth): retire annex-auth's OIDC provider after the cutover
auth.cubityfir.st is now the cubityfirst-auth worker's Custom Domain.
Remove annex-auth's two auth.cubityfir.st zone routes (a deploy that kept
them would try to re-add routes on a hostname another Worker owns) and the
now-unreachable provider: /oauth/{authorize,token,userinfo,jwks},
/.well-known/openid-configuration, the /admin/oauth/clients management
handlers, OIDC_ISSUER/OIDC_AUTHORIZE_URL, RATE_LIMITER_OIDC and the
OIDC_PRIVATE_KEY secret. The scheduled sweep stays. Docs, memories and
the key/client helper scripts that described Annex as the provider are
replaced by a pointer to auth.cubityfir.st.
Touches only packages/auth, docs, memories, scripts and CLAUDE.md, so it
can be cherry-picked onto main and shipped with the next annex-auth deploy.
* feat(admin): admin panel signs in through auth.cubityfir.st; sync account deletions (#25)
* feat(admin): sign in to the admin panel through auth.cubityfir.st
The admin panel is its own first-party OIDC client (scopes openid profile
email roles; sign-in requires the admin role, re-checked live via the
identity service). It reuses the API worker's sign-in flow (now a shared
AuthFlow: login/callback/exchange/logout) with an 'admin' session kind, and
server-side OIDC requests go over the IDENTITY_OIDC service binding.
Removed what moved to auth.cubityfir.st: the docs-app handoff, the OAuth
clients tab, and account moderation (disable/suspend/re-enable, force
password change). Standing shows as read-only from the users mirror, with
a live refresh in user details and links to manage the account there.
Delayed deletion now deletes Annex data only: scheduling blocks the person
from Annex, the cron removes sites/orgs the operator confirmed, Stripe,
memberships, billing, preferences and sessions, and marks the schedule
completed. The users row and schedule stay, so they remain blocked until
the identity account is deleted on auth.cubityfir.st. All admin data now
lives in cubedocs-main; no AUTH_DB or AUTH binding.
* feat(api): sync account deletions from auth.cubityfir.st
An hourly cron polls IdentityService.listDeletedUsers from the newest
deletion already recorded in identity_deletions and removes each deleted
account's Annex data: the Stripe customer (cancelling Ink), memberships,
API keys, doc shares, favourites, avatars and the users mirror row
(cascading sessions, billing, preferences and any admin deletion).
Sites and organizations they owned are kept with their owner rows and
listed in the admin panel's Projects page for an operator to review.
Failures (e.g. Stripe) stay pending with last_error and retry hourly.
Drops cleanupDeletedAccount, which deleted owned sites and had no caller
left after DELETE /me moved to the identity service.
* chore(oidc): remove annex-auth, harden the client after review, port e2e to the new sign-in (#26)
* chore: remove packages/auth (annex-auth) now that nothing depends on it
Identity lives on auth.cubityfir.st and everything Annex-specific moved
into the api worker, so the annex-auth worker package goes: root
dev/build/deploy/typecheck/test scripts, the auth migrations step,
d1-local's "auth" database and e2e's auth-DB calls (account data is in
cubedocs-main now). The cubedocs-auth schema survives as a fixture for the
one-time import script. Admin + admin-frontend tests join the root
`pnpm test`, and `dev:stripe` forwards to the api worker.
Adds e2e/signIn.ts (dev quick-login) for porting the e2e suites, which
still drive Annex's old registration and login forms.
* docs: describe Annex as a client of auth.cubityfir.st
CLAUDE.md's auth section, schema notes, admin deletion, worker config and
local-dev notes now describe the OIDC client model: Annex sessions and the
users mirror in cubedocs-main, the IDENTITY RPC and IDENTITY_OIDC bindings
(and why same-zone fetches must use the binding), the deletion sync, and
the e2e suites that still need porting. New memories/Identity-Client.md
covers the flow, client registration and the cutover steps;
.dev.vars.example files show how to point local dev at a local identity
worker. Ink-Stripe, Api-Keys, Collab, Worktree-Dev, README and
CONTRIBUTING drop the auth worker.
* fix(oidc): harden sign-in handoff, deletion and billing paths after review
- The single-use handoff code now travels only in an HttpOnly,
SameSite=Strict cookie (never in a URL), so a crafted /auth/complete
link can't sign anyone in (login CSRF).
- A recorded or persisted identity deletion wins over the standing cache,
the mirror fallback and any in-flight mirror refresh (sessions, API
keys, collab); deleted owners' kept member rows are scrubbed.
- Admin deletion: the live admin role is required at scheduling and
re-checked before execution; the point of no return is tied to the
Stripe customer the preflight saw.
- Stripe webhook: billing upserts are guarded against tombstones; a
blocked event deletes its customer, an unknown user is retried, never
cleaned up without evidence.
- Invite-by-email no longer falls back to the mirror outside local dev;
Stripe customer email follows identity email changes seen by the
standing check.
- Admin sign-in lands on its deep link; deletion-sync paging can't skip
or stall on same-millisecond deletions; import script arg parsing.
- Cutover doc: freeze window, Stripe replay, clients disabled until
deletions are reconciled against a final export.
* fix(oidc): use the registered docs client and its exact post-logout URI
Sets OIDC_CLIENT_ID to the client registered at auth.cubityfir.st
(oidc_7369d6d5736d2bea35f1ab47). The provider matches post-logout
redirect URIs byte for byte and the registration is the bare origin, so
the default no longer appends a trailing slash (verified against the live
provider: the bare origin is accepted, the slashed form is refused).
Adds scripts/oidc-check.mjs: a dev-machine end-to-end check of the
registration (real sign-in, code exchange, the worker's id_token checks,
claims printed; secret read from the environment, never printed).
* fix(oidc): per-attempt handoff cookie and Stripe email sync on every mirror write
Each sign-in now gets its own handoff cookie (annex_handoff_<attempt>),
named by a non-secret attempt id the completion page passes back, so two
sign-ins finishing at once in one browser each redeem their own session.
refreshMirror reads the previous email in the same batch and updates the
linked Stripe customer when it changes, so whichever path writes a new
address first (sign-in, standing check, invite lookup, admin) keeps
receipts in step.
* fix(oidc): per-sign-in login-state cookie; reconcile accounts added after the identity import
The login-state cookie is now annex_oidc_<state>, so sign-ins started in
two tabs before either callback don't overwrite or clear each other's
state.
The cutover runbook now reconciles additions as well as deletions:
accounts registered on the old Annex after the identity service's import
must be added there with their original ids before the clients are
enabled, or their Annex data is stranded under an id nobody can sign in as.
* docs(oidc): freeze old Annex sign-ups before the cutover export
* fix(api): keep the deletion-sync cron constant out of the worker entry module
workerd loads every named export of the main module as an entrypoint, so
exporting the cron string from src/index.ts stopped annex-api from
starting. Moved it to lib/identityDeletions.ts, with a test that the
entry module exports only handlers and classes.
* feat(admin): localhost-only dev quick-login for the admin panel
POST /api/dev/quick-login on the admin worker mints an admin dev user and
an admin session, gated like the api worker's (DEV_QUICK_LOGIN=true AND a
localhost APP_ORIGIN), so the admin e2e suite runs without a local
identity service.
* test(e2e): sign in with the dev quick login instead of Annex's old forms
Every suite now signs in through e2e/signIn.ts (devSignIn); the admin
suite uses the admin worker's quick login. Drops the Turnstile mocks and
the 2FA, change-email and change-password suites, whose features moved to
auth.cubityfir.st.
* test(e2e): scope the admin smoke test to this run's user and audit entry
* chore(admin): use the registered auth.cubityfir.st client id for the admin panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Accounts now live on the standalone identity service at auth.cubityfir.st (cutover 2026-11-18, new signing key). Annex still reads
cubedocs-authand proxiesannex-auth, so account data has started to drift between the two. This stack makes Annex an ordinary OpenID Connect client of the identity service.This PR moves the API worker over:
/api/auth/login→ auth.cubityfir.st (PKCE S256, state, nonce) →/api/auth/callbackverifies the id_token against the JWKS and hands the SPA a single-use code in an HttpOnly, SameSite=Strict cookie (never in a URL), which/api/auth/exchangetrades for the session JWT. Sign-out revokes the session and returns the provider's end-session URL.IDENTITY_OIDCservice binding, not a public fetch: Annex shares the cubityfir.st zone, and a same-zonefetch()would reach the origin instead of the identity worker. Account standing comes from theIDENTITYRPC binding (cached ~60s, mirror fallback).usersmirror, Annexsessions, and the Annex-only tables (billing, preferences, webhook events, deletions, audit).scripts/import-auth-data.mjscopies them once from acubedocs-authexport./meroutes move frompackages/authinto the API worker; everyAUTH_DBread andAUTHproxy is gone.Requests over a service binding carry no client IP, so all of Annex's token calls share one 100/min bucket on the provider.
Nothing here deploys or touches remote data; the cutover steps are in
memories/Identity-Client.md(PR 4).Stack (merge in order; each PR's diff is only its own commits):
mainpackages/auth, review hardening, docs, e2e portReviewed with sol-loop: 9 rounds with gpt-6.2-sol. Sol verdict: approved