WIP: FORGE-504: Sign in with gmacko, off by default (NATH-23) #1328

Draft
gmackie wants to merge 2 commits from feat/FORGE-504-NATH-23-gmacko-sign-in into main
Owner

Kanbanger: FORGE-504 (https://tasks.gmac.io/gmacko/issue/FORGE-504), part of NATH-23.

Draft. Do not merge until beta verification and an independent security review are done.

What this changes

"Sign in with gmacko" (providerId nathan) becomes one more sign-in option on ForgeGraph. It is off by default: the provider and the button exist only when NATHAN_ISSUER, NATHAN_CLIENT_ID and NATHAN_CLIENT_SECRET are all set for a stage. No stage sets them today, so merging this changes nothing at runtime.

  • Kit: gmackie/nathan#48 kit/better-auth-gmacko/gmacko.ts @ 34bd5f0, vendored byte-identical as apps/web/src/lib/gmacko.ts.
  • ForgeGraph wiring is in apps/web/src/lib/gmacko-provider.ts:
    • A partial or malformed configuration disables gmacko alone and logs only the setting names.
    • An explicit gmacko link (POST /oauth2/link) is refused, because ForgeGraph sets allowDifferentEmails.
  • Sign-in uses genericOAuth with pinned endpoints, PKCE S256 and a nonce. On Better Auth 1.6 the exact redirect URI is https://<host>/api/auth/oauth2/callback/nathan.
  • CREA-12 linking: a Nathan-verified email, a verified local email and one subject per issuer. Accounts are keyed issuer#sub, and posted ID tokens are refused.
  • New gmacko users get a username and a Forgejo account, as SSO users do (owner decision 5), with a collision check (apps/web/src/lib/forge-username.ts). Forgejo signs in through ForgeGraph's OIDC provider and matches accounts by username, so a username is kept only after Forgejo has created an account for it.
    • Names a ForgeGraph user already holds are skipped.
    • A name Forgejo refuses (409/422) moves on to the next candidate, up to base-5.
    • Any other failure leaves the username unset.
    • The SSO path is unchanged.
  • Unchanged: the oidcProvider and every trusted client (Forgejo, Veritas, FabForge, Preflight, Creator, NetControl, plus Kanbanger's DB client), GitHub, Google, Microsoft, Apple, SSO, CLI device codes, PATs, and the git, registry and MCP tokens.

Plan and open owner decisions: docs/plans/2026-12-01-forge-504-gmacko-sign-in.html

Checks (local)

  • apps/web: tsc --noEmit clean. oxlint shows warnings only.
  • vitest run: 381 files, 3190 tests passed at 04a36eeb9. 398b100d5 adds forge-username.test.ts (7 tests). This includes the new gmacko-provider.test.ts, which runs a real Better Auth 1.6.11 instance and checks:
    • the authorize URL, exact redirect URI, S256 and nonce;
    • the explicit-link refusal and the posted-ID-token refusal;
    • that GitHub is unaffected;
    • that a partial configuration doesn't leak the secret.

Forgejo CI on 398b100d5: every lane is green except CI / ci, which fails on purpose while the PR is a draft ("Draft validation is incomplete"). The full required run happens when the PR is marked ready.

Owner decisions (2026-12-01)

  1. Beta gets its own child, id.beta.forgegraf.com.
  2. Each OIDC client is removed after its app has gmacko in production, one PR per client.
  3. Forgejo will sign in at id.gmac.io. It moves last, and every account re-links.
  4. NetControl becomes an application on id.gmac.io.
  5. gmacko users get a Forgejo account now, with a collision check (in this PR).
  6. The trusted-client list shrinks as clients move. Then the oidcProvider is retired.

Before leaving draft

  1. Child id.beta.forgegraf.com provisioned, outside Access. Client registered disabled with the exact redirect URI. Secrets delivered to forgegraf-beta.
  2. PR head deployed to beta. Verified: a new user, an existing verified user, an existing unverified user (refused), a Forgejo OIDC resume, and CLI login.
  3. Independent security review.

🤖 Generated with Claude Code

Kanbanger: FORGE-504 (https://tasks.gmac.io/gmacko/issue/FORGE-504), part of NATH-23. **Draft. Do not merge** until beta verification and an independent security review are done. ## What this changes "Sign in with gmacko" (providerId `nathan`) becomes one more sign-in option on ForgeGraph. It is **off by default**: the provider and the button exist only when `NATHAN_ISSUER`, `NATHAN_CLIENT_ID` and `NATHAN_CLIENT_SECRET` are all set for a stage. No stage sets them today, so merging this changes nothing at runtime. - Kit: gmackie/nathan#48 `kit/better-auth-gmacko/gmacko.ts` @ 34bd5f0, vendored byte-identical as `apps/web/src/lib/gmacko.ts`. - ForgeGraph wiring is in `apps/web/src/lib/gmacko-provider.ts`: - A partial or malformed configuration disables gmacko alone and logs only the setting names. - An explicit gmacko link (`POST /oauth2/link`) is refused, because ForgeGraph sets `allowDifferentEmails`. - Sign-in uses genericOAuth with pinned endpoints, PKCE S256 and a nonce. On Better Auth 1.6 the exact redirect URI is `https://<host>/api/auth/oauth2/callback/nathan`. - CREA-12 linking: a Nathan-verified email, a verified local email and one subject per issuer. Accounts are keyed `issuer#sub`, and posted ID tokens are refused. - New gmacko users get a username and a Forgejo account, as SSO users do (owner decision 5), with a collision check (`apps/web/src/lib/forge-username.ts`). Forgejo signs in through ForgeGraph's OIDC provider and matches accounts by username, so a username is kept only after Forgejo has created an account for it. - Names a ForgeGraph user already holds are skipped. - A name Forgejo refuses (409/422) moves on to the next candidate, up to `base-5`. - Any other failure leaves the username unset. - The SSO path is unchanged. - Unchanged: the oidcProvider and every trusted client (Forgejo, Veritas, FabForge, Preflight, Creator, NetControl, plus Kanbanger's DB client), GitHub, Google, Microsoft, Apple, SSO, CLI device codes, PATs, and the git, registry and MCP tokens. Plan and open owner decisions: `docs/plans/2026-12-01-forge-504-gmacko-sign-in.html` ## Checks (local) - `apps/web`: `tsc --noEmit` clean. oxlint shows warnings only. - `vitest run`: 381 files, 3190 tests passed at 04a36eeb9. 398b100d5 adds `forge-username.test.ts` (7 tests). This includes the new `gmacko-provider.test.ts`, which runs a real Better Auth 1.6.11 instance and checks: - the authorize URL, exact redirect URI, S256 and nonce; - the explicit-link refusal and the posted-ID-token refusal; - that GitHub is unaffected; - that a partial configuration doesn't leak the secret. Forgejo CI on 398b100d5: every lane is green except `CI / ci`, which fails on purpose while the PR is a draft ("Draft validation is incomplete"). The full required run happens when the PR is marked ready. ## Owner decisions (2026-12-01) 1. Beta gets its own child, `id.beta.forgegraf.com`. 2. Each OIDC client is removed after its app has gmacko in production, one PR per client. 3. Forgejo will sign in at `id.gmac.io`. It moves last, and every account re-links. 4. NetControl becomes an application on `id.gmac.io`. 5. gmacko users get a Forgejo account now, with a collision check (in this PR). 6. The trusted-client list shrinks as clients move. Then the oidcProvider is retired. ## Before leaving draft 1. Child `id.beta.forgegraf.com` provisioned, outside Access. Client registered disabled with the exact redirect URI. Secrets delivered to `forgegraf-beta`. 2. PR head deployed to beta. Verified: a new user, an existing verified user, an existing unverified user (refused), a Forgejo OIDC resume, and CLI login. 3. Independent security review. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(auth): FORGE-504 add Sign in with gmacko, off by default (NATH-23)
Some checks failed
Preview / deploy (pull_request) Has been skipped
Preview / cleanup (pull_request) Has been skipped
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
CI / superseded (pull_request) Successful in 34s
CI / storybook (pull_request) Has been skipped
CI / web-build (pull_request) Has been skipped
CI / gitleaks (pull_request) Successful in 22s
Registry deps hash / inputs (pull_request) Successful in 1m5s
CI / database (pull_request) Has been skipped
CI / database-d1 (pull_request) Has been skipped
CI / checks (pull_request) Successful in 3m23s
CI / go (pull_request) Successful in 1m45s
CI / unit-web (pull_request) Successful in 4m48s
CI / ci (pull_request) Failing after 1m13s
Registry deps hash / rebuild (pull_request) Successful in 5m45s
Registry deps hash / pnpm-deps-hash (pull_request) Successful in 3s
04a36eeb9a
Adds gmacko (providerId nathan) as one more Better Auth sign-in option,
through the Nathan kit (gmackie/nathan kit/better-auth-gmacko @ 34bd5f0,
vendored unchanged as apps/web/src/lib/gmacko.ts).

- Off unless NATHAN_ISSUER, NATHAN_CLIENT_ID and NATHAN_CLIENT_SECRET are
  all set for the stage. A partial or malformed configuration disables
  only gmacko and logs the setting names, never their values.
- genericOAuth with pinned endpoints, PKCE S256 and a nonce. The exact
  redirect URI on Better Auth 1.6 is <host>/api/auth/oauth2/callback/nathan.
- CREA-12 linking: Nathan-verified email, verified local email, one
  subject per issuer, accounts keyed issuer#sub, posted ID tokens refused.
- ForgeGraph sets allowDifferentEmails, so an explicit gmacko link
  (POST /oauth2/link) is refused. A gmacko identity attaches to an existing
  user only on a first redirect sign-in.
- The login button appears only where the provider is configured.
- The oidcProvider, its trusted clients, social providers, SSO, device
  codes and tokens are unchanged.

Plan and owner decisions: docs/plans/2026-12-01-forge-504-gmacko-sign-in.html

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feat(auth): FORGE-504 provision a checked username and Forgejo account for gmacko users
Some checks failed
Preview / deploy (pull_request) Has been skipped
Preview / cleanup (pull_request) Has been skipped
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
Registry deps hash / inputs (pull_request) Successful in 38s
Registry deps hash / rebuild (pull_request) Successful in 4m16s
Registry deps hash / pnpm-deps-hash (pull_request) Successful in 2s
CI / superseded (pull_request) Successful in 3s
CI / database (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / web-build (pull_request) Has been skipped
CI / database-d1 (pull_request) Has been skipped
CI / gitleaks (pull_request) Successful in 18s
CI / go (pull_request) Successful in 51s
CI / unit-web (pull_request) Successful in 1m13s
CI / checks (pull_request) Successful in 1m44s
CI / ci (pull_request) Failing after 10s
398b100d52
Owner decision 5 (2026-12-01): gmacko users get a Forgejo account at
sign-up, as SSO users do, with a collision check.

Forgejo signs in through ForgeGraph's OIDC provider and matches accounts
by username, so a username is kept only after Forgejo has created an
account for it. Names a ForgeGraph user already holds are skipped. A name
Forgejo refuses (409/422: taken by a user or org, or reserved) moves on to
the next candidate, up to base-5. Any other failure leaves the username
unset. The hook runs on account.create.after for providerId nathan and
never blocks sign-in. The SSO path is unchanged.

The plan records all six owner decisions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Owner decisions for FORGE-504 (2026-12-01), from the planning thread. #1329 duplicated this PR and is closed in favor of this one.

  • D1, Forgejo sign-in: git.forgegraf.com moves to id.gmac.io directly, in a follow-up issue. That issue covers username mapping and Forgejo's [oauth2_client] ACCOUNT_LINKING, so a gmacko subject never auto-links to an existing login. Keep the "forgegraph" auth source until every user has linked.
  • D2, NetControl: moves to id.gmac.io directly, in NetControl's own issue.
  • D3, Forgejo account for gmacko sign-ups: the same as Google, Microsoft and Apple. No username at sign-up, so ensureForgejoUser creates the account lazily. No usernames derived from the email's local part.
  • D4, trusted clients: removed one at a time. Each goes after its app runs gmacko in production and the client has issued no tokens for 30 days (add per-client issuance telemetry first). One PR per client.
  • D5, beta child: id.beta.forgegraf.com is provisioned once nathan #48 merges.

The HTML plan is at docs/plans/2026-12-01-forge-504-gmacko-sign-in.html on branch FORGE-504-gmacko-sign-in, commit e81eb8f86. Cherry-pick it if you want it in-tree.

Points from #1329 worth checking here:

  • The kit suite (node:test) passes on better-auth 1.6.11 itself: 18 pass, 0 fail, 1 skipped.
  • @better-auth/core@1.6.11 and jose@6.2.3 are added as direct apps/web dependencies. The lockfile only gains importer entries. A plain pnpm install locally also rewrote unrelated @cloudflare/workers-types peer resolutions, so check the lockfile diff.
  • Pre-existing risk: preferred_username falls back to the email's local part (auth.ts:138). If Forgejo links accounts by username, a user without a username could land on someone else's Forgejo account. Verify this before D1.
Owner decisions for FORGE-504 (2026-12-01), from the planning thread. #1329 duplicated this PR and is closed in favor of this one. - **D1, Forgejo sign-in:** git.forgegraf.com moves to **id.gmac.io directly**, in a follow-up issue. That issue covers username mapping and Forgejo's `[oauth2_client] ACCOUNT_LINKING`, so a gmacko subject never auto-links to an existing login. Keep the "forgegraph" auth source until every user has linked. - **D2, NetControl:** moves to **id.gmac.io directly**, in NetControl's own issue. - **D3, Forgejo account for gmacko sign-ups:** the same as Google, Microsoft and Apple. No username at sign-up, so ensureForgejoUser creates the account lazily. No usernames derived from the email's local part. - **D4, trusted clients:** removed one at a time. Each goes after its app runs gmacko in production and the client has issued no tokens for 30 days (add per-client issuance telemetry first). One PR per client. - **D5, beta child:** id.beta.forgegraf.com is provisioned once nathan #48 merges. The HTML plan is at `docs/plans/2026-12-01-forge-504-gmacko-sign-in.html` on branch `FORGE-504-gmacko-sign-in`, commit e81eb8f86. Cherry-pick it if you want it in-tree. Points from #1329 worth checking here: - The kit suite (node:test) passes on better-auth **1.6.11** itself: 18 pass, 0 fail, 1 skipped. - `@better-auth/core@1.6.11` and `jose@6.2.3` are added as direct apps/web dependencies. The lockfile only gains importer entries. A plain `pnpm install` locally also rewrote unrelated `@cloudflare/workers-types` peer resolutions, so check the lockfile diff. - Pre-existing risk: `preferred_username` falls back to the email's local part (`auth.ts:138`). If Forgejo links accounts by username, a user without a username could land on someone else's Forgejo account. Verify this before D1.
Some checks failed
Preview / deploy (pull_request) Has been skipped
Preview / cleanup (pull_request) Has been skipped
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
Registry deps hash / inputs (pull_request) Successful in 38s
Registry deps hash / rebuild (pull_request) Successful in 4m16s
Registry deps hash / pnpm-deps-hash (pull_request) Successful in 2s
CI / superseded (pull_request) Successful in 3s
CI / database (pull_request) Has been skipped
CI / storybook (pull_request) Has been skipped
CI / web-build (pull_request) Has been skipped
CI / database-d1 (pull_request) Has been skipped
CI / gitleaks (pull_request) Successful in 18s
Required
Details
CI / go (pull_request) Successful in 51s
CI / unit-web (pull_request) Successful in 1m13s
CI / checks (pull_request) Successful in 1m44s
CI / ci (pull_request) Failing after 10s
Required
Details
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/FORGE-504-NATH-23-gmacko-sign-in:feat/FORGE-504-NATH-23-gmacko-sign-in
git switch feat/FORGE-504-NATH-23-gmacko-sign-in
Sign in to join this conversation.
No description provided.