Skip to content

feat: native app social sign-in with PKCE code exchange and expo client - #221

Merged
thegdsks merged 1 commit into
mainfrom
feat/mobile-social-signin
Oct 13, 2026
Merged

thegdsks merged 1 commit into
mainfrom
feat/mobile-social-signin

Conversation

@thegdsks

Copy link
Copy Markdown
Member

Native apps could not complete a social sign-in: the OAuth callback sets a cookie and redirects to a web URL, and a session token must not go in a redirect URL. This adds the RFC 8252 flow with PKCE and wires it into the expo package.

Server (oauth plugin)

New option mobile: { redirectUris }, off when omitted.

  1. GET /auth/oauth/authorize/:provider accepts mobile_redirect (exact match against the allowlist) and an S256 code_challenge. The pending flow is stored as a one-time token and tied to the browser with an HttpOnly cookie.
  2. After the callback, the sign-in gate and the email-linking rules run as before. The browser is then redirected to the app with a 60 second single-use code. No session cookie is set.
  3. POST /auth/oauth/mobile/exchange takes { code, code_verifier }, checks S256, and returns { data: { token, user, expiresAt } }. A wrong verifier burns the code.
  4. Failures go back to the app as ?error=. A required second factor arrives as the usual #gate= fragment on the app URI.

Expo client

  • signInWithProvider and useSocialSignIn. The browser and crypto functions are injected (openAuthSession, randomBytes, sha256), so the package takes no hard dependency on expo-web-browser or expo-crypto.
  • createSecureStoreStorage(SecureStore).
  • appState option: the session is re-checked when the app returns to the foreground.

Behavior to know about

  • theauth_one_time_tokens is now created whenever the oauth plugin is registered (before: only with magic link, email OTP or password reset). The exchange codes live there.
  • Nothing changes for existing apps unless mobile is set. New exports and options only, so minor bumps for core and expo.

Verified

  • core: 7 new tests (full flow, replay, wrong verifier, allowlist, off by default, web flow unchanged, gate, error redirect). 476 tests across the oauth, one-time-token and migration suites pass. tsc clean.
  • expo: 6 new tests plus the existing 2 pass, tsc clean.

Not verified

  • No run on a device or simulator. The expo-web-browser and expo-crypto snippets in docs/expo.mdx follow their documented signatures but were not executed.
  • The cookie that ties the flow to the browser relies on the system browser session keeping cookies between the authorize and callback steps. That holds for ASWebAuthenticationSession and Custom Tabs by default, but not with ephemeral sessions (preferEphemeralSession).
  • Which path the expo basePath mounts the OAuth plugin routes under depends on the host app. The docs say it must expose /auth/oauth/....
  • Passkeys and DPoP key binding for mobile are not part of this PR.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your first pull request. CI will run shortly. If the change touches package source, please add a changeset with pnpm changeset.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@thegdsks
thegdsks merged commit bf91c2f into main Oct 13, 2026
11 of 12 checks passed
@thegdsks
thegdsks deleted the feat/mobile-social-signin branch October 13, 2026 16:58
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.62420% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/core/src/auth/oauth/plugin.ts 87.64% 10 Missing and 1 partial ⚠️
packages/core/src/auth/oauth/mobile.ts 85.07% 7 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant