feat(github-oauth): real GitHub OAuth flow + identity resolution + claim-pending handoff#41
Merged
Merged
Conversation
themightychris
added a commit
that referenced
this pull request
May 17, 2026
…ng handoff
Replaces the 501 stubs at /api/auth/github/{start,callback} with the full
spec-compliant flow per specs/api/auth.md and specs/behaviors/account-migration.md.
- Hand-rolled PKCE (S256) + 32-byte CSPRNG state cookie (HttpOnly, SameSite=Lax)
- 10-min signed cfp_oauth_session JWT carries { state, codeVerifier, return }
- GitHub client (token exchange + /user + /user/emails) using built-in fetch
- Account-matching algorithm: byGithubUserId → email match → username weak match
- Three callback outcomes wired into auth-jwt-substrate's mintSessionFor /
issueClaimPending:
* existing-linked → refresh login+email, mint session, redirect to return
* create-fresh → write Person + PrivateProfile via store.transact, mint session
* candidates → mint claim-pending JWT (scope:claim, 5m), redirect /account-claim
- Error redirects to /login?error=… for access_denied, oauth_state_mismatch,
oauth_session_invalid, github_unreachable, email_unverified
15 new tests across the three callback outcomes + every documented error mode (CSRF mismatch, expired oauth session, GitHub denial, email_unverified, token-exchange error). Each test uses a unique remoteAddress to dodge the 10-req/min/IP cap on /api/auth/*. Trims the OAuth 501-stub tests from auth.test.ts now that the real handlers redirect instead of returning 501. Extends createGitHubMock with the github.com/login/oauth/access_token endpoint plus a setTokenResponse override for the error-path tests.
Temporary landing page for the candidate-match callback path. The full account-claim screens land in the next plan; this placeholder gives a recognizable end-of-flow for the github-oauth tests + manual QA so the redirect target isn't a 404.
f1479fb to
0ceaed8
Compare
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.
Summary
Replaces the
auth-jwt-substrate501 stubs at/api/auth/github/{start,callback}with the real OAuth flow per specs/api/auth.md and specs/behaviors/account-migration.md.cfp_oauth_statecookie; 10-min signedcfp_oauth_sessionJWT carries{ state, codeVerifier, return }/user+/user/emailsvia Node's built-in fetch; verified-only email filterbyGithubUserId→ email match → username weak matchmintSessionFor/issueClaimPending:githubLogin+PrivateProfile.email, mint session, redirect to returnPerson+PrivateProfileviastore.transact(private-first), mint sessionclaim, 5m), redirect/account-claim?return=…/login?error=<code>/account-claimplaceholder page inapps/webTest plan
Person+PrivateProfile→ session issued → redirected to/githubUserId→ callback refreshesgithubLogin+ email → session, no shadow account createdcfp_claimcookie set, redirect to/account-claimstatequery param →/login?error=oauth_state_mismatch/login?error=github_unreachableerror=access_denied) →/login?error=access_denied/login?error=email_unverifiedcfp_oauth_sessioncookie →/login?error=oauth_session_invalidnpm run type-check,npm run lint,npm run buildall greenmain; passes cleanly with--no-file-parallelism