Repository navigation
feat(oauth): ask TanStack Source for its two-factor check before a source grant - #1649
AlemTuzlak wants to merge 2 commits into
Conversation
…urce grant For scope `source`, the authorize page asks TanStack Source whether the person's Source account needs its two-factor check. When it does, the primary button sends the person to Source, which returns a signed `source_check` assertion. tanstack.com verifies it, shows "Confirmed in TanStack Source" and the normal Authorize button, and never authorizes on its own. The authorization code stores `source_two_factor_at`, the token exchange and refresh rotation copy it, and introspection returns it when set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Page sizes sum the JS and CSS in the TanStack Start manifest for each route and its layouts. Shared files count once per page. Compared with main at |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
tanstack-com | fff3796 | Commit Preview URL Branch Preview URL |
Dec 04 2026, 02:48 PM |
|
AI review notes for 892be3c: the assertion is verified again when the code is created, and the diff carries its timestamp through code exchange, refresh rotation and introspection. I haven't run this flow against Source. The remaining verification gap is that the new tests only cover the hash, verifier and URL helper. Could you add a database-backed test that issues a source code with a valid assertion, exchanges it, rotates its refresh token and checks the introspection timestamp, plus a grant without an assertion and a rejected assertion that creates no code? Type checking won't catch a missing copy or persistence step in that chain. Could you also link the Source-side change and its enforcement tests or deployment evidence? This still needs the required auth/database reviewer before landing. |
Issue a source code with a verified check, exchange it, rotate the refresh token twice and check introspection at each step. Also cover a check for an account with two-factor off, a grant without a check, and rejected checks that create no code. The test runs in the chat-runtime job, on the database built from the site baseline and every migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, both points are addressed in fff3796. Database-backed test.
It runs in the "Chat PostgreSQL runtime" job, on the database built from Source side. It is merged and deployed: https://source.tanstack.com/@TanStack/source/pull/1413 (merge
The contract. Yes, the fail-open is intended. tanstack.com never decides whether two-factor is needed; it only carries Source's signed answer. If Existing grants
Agreed it still needs the auth/database reviewer. I won't merge it. |
|
AI review follow-up for fff3796: thanks, the new test exercises the real issuance, exchange, two refresh rotations and introspection paths, including rejected checks creating no code. I checked the PostgreSQL job log: all 5 tests passed with 0 skipped. That addresses the database lifecycle gap I raised. The Source contract and existing-grant behavior are now documented in your reply. I couldn't retrieve the linked Source PR through my reader, so I haven't independently verified that side or its deployment. The auth/database reviewer should check that evidence before signing off. I haven't run a live two-factor flow. |
TanStack Source now supports two-factor authentication. A
sourcegrant from tanstack.com never passes Source's own second factor, so Source refuses tanstack.com MCP tokens for accounts that have two-factor sign-in on, unless introspection says the person passed Source's check for that grant. This PR adds that check to thesourceconsent flow.Flow
/oauth/authorizewith scopesource, the loader asks Source (server to server, with the existing shared introspection secret) whether this person's Source account needs the check:POST https://source.tanstack.com/auth/tanstack/two-factor/requiredwithsuband the verifiedgithub_id. Any failure or timeout (5 s) counts as "not required", so the page works exactly as today when Source is unreachable. Source still enforces the rule on its side.https://source.tanstack.com/auth/tanstack/two-factor, which checks the person's Source session and second factor, then returns to this authorize URL withsource_check.source_checkand shows "Confirmed in TanStack Source." with the normal Authorize button. The person still clicks Authorize: the page never authorizes on its own.createAuthorizationCodeverifies the assertion again on the server and storessource_two_factor_aton the code. The code exchange and each refresh rotation copy it to the new tokens, and/oauth/introspectreturnssource_two_factor_atwhen the token has one.The assertion
source_check=<P>.<SIG>Pis base64url JSON{v: 1, sub, request, two_factor_at, exp}.requestbinds the check to one authorize request: base64url SHA-256 ofclient_id\nredirect_uri\ncode_challenge.SIGis HMAC-SHA256 with the shared secret overtanstack-source-two-factor-check-v1.<P>.v,subequals the signed-in user,requestmatches, andexpis in the future.source_two_factor_at,source_check, the two Source paths and the HMAC context string are a contract with TanStack Source, so please don't rename them.Changes
src/auth/source-two-factor.server.ts(new): the secret lookup, now shared withhandleIntrospection, therequesthash, assertion verification, the required call and the check URL.src/routes/oauth/authorize.tsx,src/utils/oauthClient.functions.ts:source_checkin the search params, the confirm step and thecheckSourceTwoFactorserver function.src/auth/oauthClient.server.ts: stores and copiessource_two_factor_at; introspection returns it.drizzle/migrations/0045_source_two_factor.sql: a nullablesource_two_factor_at bigint(epoch seconds) on the threeoauth_mcp_*tables, made withdrizzle-kit generate.tests/source-two-factor.test.ts: therequesthash, a pinned interop vector (the same vector was checked against Source's signer), and the refusals for a bad signature, the wrong sub or request, an expired or malformed assertion, and the wrong version.Checks
test:tscpasses, andlint:codehas 0 errors (109 warnings, the same as main, none in these files).tests/source-two-factor.test.ts: 5/5 pass.test:unitlocally: 733 pass, 1 fail. The failure istests/worker-boundaries.test.ts(URLPattern is not defined), which comes from running Node 22 locally instead of the.nvmrc25.9, and has nothing to do with this change.tsc.Source's side (both endpoints) is in TanStack Source's own repository and ships first. Until it is live, the required call fails and this PR changes nothing.
🤖 Generated with Claude Code
Summary by CodeRabbit