[PR #7720] [MERGED] feat(oauth-proxy): rewrite to support distributed environments #15760

Closed
opened 2026-04-13 10:12:44 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7720
Author: @bytaesu
Created: 1/31/2026
Status: Merged
Merged: 2/3/2026
Merged by: @bytaesu

Base: canaryHead: 2026-01-31/feat/oauth-proxy-passthrough-mode


📝 Commits (10+)

  • 0c44a78 fix: rewrite oauth-proxy
  • 5a8cdc3 fix: use parseGenericState to handle state
  • 0e90a47 refactor: refine codes
  • 9dadd45 fix: lint
  • 19df751 Merge branch 'canary' into 2026-01-31/feat/oauth-proxy-passthrough-mode
  • e5fd440 fix(oauth-proxy): add validation for required payload fields
  • 313ea80 docs: update content
  • cbf76a2 refactor: remove types file
  • b145e0a fix: drop error-code
  • e2113f6 fix: clean up state first

📊 Changes

5 files changed (+695 additions, -519 deletions)

View changed files

📝 docs/content/docs/plugins/oauth-proxy.mdx (+26 -48)
📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+245 -264)
📝 packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts (+404 -179)
packages/better-auth/src/plugins/oauth-proxy/types.ts (+0 -23)
📝 packages/better-auth/src/plugins/oauth-proxy/utils.ts (+20 -5)

📄 Description

Summary by cubic

Rewrote the OAuth proxy to a secure passthrough mode that transfers encrypted profile data instead of cookies. This enables cross-origin OAuth without Set-Cookie hacks and creates users/sessions only on the preview environment.

  • New Features

    • Passthrough flow: production exchanges the code, builds an encrypted profile payload, and redirects to preview with profile and callbackURL.
    • Preview callback decrypts profile, validates timestamp and required fields (maxAge), creates/links user and account via handleOAuthUserInfo, sets the session cookie, and redirects to callbackURL or newUserURL.
    • Works with both cookie and database state strategies, and with UUID IDs.
    • Honors provider disableSignUp and requestSignUp flags; strict payload validation; standardized error codes and errorURL redirects.
    • Safer and simpler cross-origin behavior; no reliance on Set-Cookie forwarding.
    • Better URL resolution in checkSkipProxy and resolveCurrentURL (uses opts.currentURL, env, or baseURL).
  • Migration

    • The oauth-proxy-callback now expects a profile query param (encrypted payload) instead of cookies.
    • Set productionURL/currentURL if needed; consider configuring maxAge (e.g., 30–60s).

Written for commit 57388f7b3b. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7720 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/31/2026 **Status:** ✅ Merged **Merged:** 2/3/2026 **Merged by:** [@bytaesu](https://github.com/bytaesu) **Base:** `canary` ← **Head:** `2026-01-31/feat/oauth-proxy-passthrough-mode` --- ### 📝 Commits (10+) - [`0c44a78`](https://github.com/better-auth/better-auth/commit/0c44a7842c8f07f897361184061c49a190d3c2ae) fix: rewrite oauth-proxy - [`5a8cdc3`](https://github.com/better-auth/better-auth/commit/5a8cdc35a4f94dcfc265e0064fc1684321517919) fix: use parseGenericState to handle state - [`0e90a47`](https://github.com/better-auth/better-auth/commit/0e90a47375d94e84580602e2c5db765e0226ca6d) refactor: refine codes - [`9dadd45`](https://github.com/better-auth/better-auth/commit/9dadd458e6563ac194dfe0aa83a24cf6f145789d) fix: lint - [`19df751`](https://github.com/better-auth/better-auth/commit/19df75151ad1c30fd23093fe5bbf998aeaf011d7) Merge branch 'canary' into 2026-01-31/feat/oauth-proxy-passthrough-mode - [`e5fd440`](https://github.com/better-auth/better-auth/commit/e5fd440b2654fa895ce89bc41b565e91b4f1fbaf) fix(oauth-proxy): add validation for required payload fields - [`313ea80`](https://github.com/better-auth/better-auth/commit/313ea80c47b498611f7080edd51250a2268b887d) docs: update content - [`cbf76a2`](https://github.com/better-auth/better-auth/commit/cbf76a2ecb05a9d5ef7279043a8c3e6baaf57a88) refactor: remove types file - [`b145e0a`](https://github.com/better-auth/better-auth/commit/b145e0af75fb2b011260eb5e4cf5638bbc4c6d23) fix: drop error-code - [`e2113f6`](https://github.com/better-auth/better-auth/commit/e2113f661f589db8dd75cbd63dcbfb582cb0ded6) fix: clean up state first ### 📊 Changes **5 files changed** (+695 additions, -519 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/oauth-proxy.mdx` (+26 -48) 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+245 -264) 📝 `packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts` (+404 -179) ➖ `packages/better-auth/src/plugins/oauth-proxy/types.ts` (+0 -23) 📝 `packages/better-auth/src/plugins/oauth-proxy/utils.ts` (+20 -5) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Rewrote the OAuth proxy to a secure passthrough mode that transfers encrypted profile data instead of cookies. This enables cross-origin OAuth without Set-Cookie hacks and creates users/sessions only on the preview environment. - **New Features** - Passthrough flow: production exchanges the code, builds an encrypted profile payload, and redirects to preview with profile and callbackURL. - Preview callback decrypts profile, validates timestamp and required fields (maxAge), creates/links user and account via handleOAuthUserInfo, sets the session cookie, and redirects to callbackURL or newUserURL. - Works with both cookie and database state strategies, and with UUID IDs. - Honors provider disableSignUp and requestSignUp flags; strict payload validation; standardized error codes and errorURL redirects. - Safer and simpler cross-origin behavior; no reliance on Set-Cookie forwarding. - Better URL resolution in checkSkipProxy and resolveCurrentURL (uses opts.currentURL, env, or baseURL). - **Migration** - The oauth-proxy-callback now expects a profile query param (encrypted payload) instead of cookies. - Set productionURL/currentURL if needed; consider configuring maxAge (e.g., 30–60s). <sup>Written for commit 57388f7b3b2bcfd47dab8c458a633b3c5ad15a0e. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 10:12:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15760