Skip to content

Connect: read-only Google sign-in for blocks that need OAuth - #156

Merged
sykosyber merged 1 commit into
mainfrom
wp/omni/connect
Oct 12, 2026
Merged

sykosyber merged 1 commit into
mainfrom
wp/omni/connect

Conversation

@sykosyber

Copy link
Copy Markdown
Member

Objective. APEX_PLAN 6.8: let a block that reads the person's own data from a provider that requires OAuth (Google first) sign in, without widening Flyspace's write surface and without keeping tokens anywhere but the session.

What changed

  • src/core/capabilities/connectProviders.ts: the providers the compiler may bind (Google: accounts.google.com, APIs on *.googleapis.com, read-only = scope ending .readonly).
  • openapi.ts: a security requirement made only of oauth2 schemes (Google pairs an implicit and an authorizationCode scheme over the same scopes) binds as one oauth auth. It requires: a connectable provider, the API on that provider's own hosts, a read operation, and an alternative whose scopes are all read-only. The narrowest such alternative is chosen. Writes are refused ("Signed-in operations are read-only in Flyspace"). Measured on the real Google Calendar v3 spec: 7 read operations compile with calendar.readonly only, 26 writes are refused. events.list is still refused for an unrelated reason (an optional array query parameter), next package.
  • src/core/services/server/oauthConnect.ts + src/app/api/oauth/**: authorization code + PKCE (S256) with the owner's client (OMNI_GOOGLE_CLIENT_ID / OMNI_GOOGLE_CLIENT_SECRET). The flow is stateless: verifier, scopes and the opener's nonce ride in an httpOnly, SameSite=Lax cookie HMAC-signed with a key derived from the client secret, bound to state, valid 10 minutes, cleared on callback. The server refuses non-read-only scopes at start, checks the granted scopes, uses access_type=online (no refresh token), passes no provider error text on, and stores and logs nothing. GET /api/oauth lists configured providers (names only). The start route refuses Sec-Fetch-Site: cross-site.
  • Callback page: sends the outcome over a same-origin BroadcastChannel (which survives the provider's COOP, unlike window.opener). Its CSP is default-src 'none' with the one inline script allowed by sha256. JSON is escaped against </script>.
  • Client src/core/capabilities/connect.ts: opens the window synchronously from the click, accepts only its own nonce and exactly the manifest's scopes, and puts the token in the manifest's slot (per origin and scope set) with sessionOnly. The token is dropped 60 s before expiry. secrets.ts: set(..., { sessionOnly }); refs() (used only by the device vault) omits session-only slots, so "Remember keys" never stores a sign-in.
  • UI: the block shows "This API needs you to sign in to Google", the read-only scopes, and "Sign in with Google" (or that the server has no client set up). The Run button reads "Sign in first"; "Sign in again" appears on a 400/401/403. The install dialog no longer asks for a typed key for an OAuth slot.
  • OMNI_GOOGLE_CLIENT_SECRET added to SECRET_ENV_VARS (bundle scan and scrubber).
  • Docs: .env.example, DEPLOYMENT.md "Connect (OAuth sign-in)", DESIGN.md, APEX_PLAN.md 6.8 status.

What did not change. No write or destructive operation can be compiled with OAuth (stop condition 3). OAuth never rides the server broker (existing rule). The public preview offers no sign-in (OMNI_PUBLIC_DEMO=1 → no providers, start 503). public/api-index.json is not rebuilt, so search still lists Google APIs as blocked until npm run catalog:build runs. AGENTS.md is not edited: a sign-in token follows its existing rule for credentials (browser memory, session only, attached to the capability's own request).

Tests run

  • npm run typecheck 0 errors; npm run lint 0 errors (8 existing warnings).
  • npm test: 1619 passed, 1 failed (fieldHarness.test.ts, the known Windows-only CRLF failure).
  • New: connect.compile.test.ts (6), oauthConnect.test.ts (11: config gating and preview, write scope refused, PKCE challenge matches verifier, client secret only in the token request, missing/forged cookie, state mismatch, expiry, unticked scope, provider error text not echoed, CSP hash, script break-out), connect.test.ts (5: re-pointed manifest gets no sign-in, nonce filtering, scope mismatch, blocked popup, expiry, vault exclusion), SignIn.component.test.tsx (3), redirectUri.test.ts (2). Fixtures and stubs only.
  • npm run build + npm run scan:bundle: PASS. npm run build:next + npm run test:e2e: 9 passed.
  • Smoke against next start with a dummy client: GET /api/oauth → {"providers":["google"]}; start → 302 to accounts.google.com/o/oauth2/v2/auth with redirect_uri=http://127.0.0.1:3123/... and a HttpOnly; SameSite=lax; Path=/api/oauth cookie; a write scope → 400; a callback without the cookie → 400 page with the hashed CSP. The smoke caught that next start reports localhost for 127.0.0.1, which would have split the cookie from the callback. Fixed: the redirect URI uses the browser's Host (or OMNI_OAUTH_ORIGIN).

Measurements. Google Calendar v3 compile counts above. No live sign-in.

Known failures. fieldHarness.test.ts on Windows only.

Claim ceiling. Implemented and tested with fixtures and stubs. No live Google sign-in has been run: no OAuth client is registered.

Architectural decisions introduced

  • OAuth binding is compile-time policy (connectProviders.ts), independent of whether a client is configured.
  • Read-only by scope name, enforced at compile, at start, and on the granted scopes.
  • Stateless flow state in a signed cookie, so it works across Worker isolates.
  • Token handoff by same-origin BroadcastChannel plus nonce.
  • "Session only" secret slots, excluded from the device vault.

Evidence that could falsify it. A compiled manifest with oauth auth for a non-GET, a non-.readonly scope, or a non-Google host. A token reaching a slot for any other origin. The device vault holding a sign-in token. A callback succeeding without the start cookie. The client secret appearing in a redirect, a cookie, a page, or .next/static.

Owner action. Register a Google OAuth client (DEPLOYMENT.md, Connect), then do the first real sign-in, e.g. Calendar calendarList.list.

Next permissible package. Compile optional compound query parameters by leaving them out (unblocks Calendar events.list), then rebuild the API index.

🤖 Generated with Claude Code

APEX_PLAN 6.8. The compiler binds Google's paired oauth2 schemes as one
`oauth` binding, only for a read operation, only with its narrowest
`.readonly` scope, and only when the API is on Google's own hosts; a write
that needs a sign-in is refused (AGENTS.md stop condition 3).

The server runs authorization code with PKCE through an owner-registered
client (OMNI_GOOGLE_CLIENT_ID/SECRET), keeping no state: the verifier,
scopes and nonce ride in a signed httpOnly cookie bound to `state`. It checks
the granted scopes, requests no refresh token, and hands the token to the
starting page over a same-origin BroadcastChannel from a callback page whose
only script is allowed by hash. The token lives in the manifest's own slot
for the session; the device vault never keeps it, and it is dropped a minute
before it expires.

The block shows "Sign in with Google" (or that the server has no client),
and "Sign in again" on a refusal. Off in the public preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sykosyber
sykosyber enabled auto-merge October 12, 2026 23:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T23:13:42.450862Z e2b2aca PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sykosyber
sykosyber merged commit c5ae01c into main Oct 12, 2026
4 checks passed
@sykosyber
sykosyber deleted the wp/omni/connect branch October 12, 2026 23:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2b2aca409

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .env.example Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant