[PR #7186] [MERGED] fix(github): surface OAuth token exchange errors #7130

Closed
opened 2026-03-13 13:25:12 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7186
Author: @Paola3stefania
Created: 1/7/2026
Status: Merged
Merged: 1/27/2026
Merged by: @himself65

Base: canaryHead: fix/github-oauth-data-error-handling


📝 Commits (8)

  • 785a8b0 fix: handle github data.error
  • 655cbd7 Merge branch 'canary' into fix/github-oauth-data-error-handling
  • 020ac7e Merge branch 'canary' into fix/github-oauth-data-error-handling
  • af0f82f address comments
  • 642a983 Merge branch 'canary' into fix/github-oauth-data-error-handling
  • 17fc96a Merge branch 'canary' into fix/github-oauth-data-error-handling
  • e4caebf Merge branch 'canary' into fix/github-oauth-data-error-handling
  • 5d9ec3e Merge branch 'canary' into fix/github-oauth-data-error-handling

📊 Changes

3 files changed (+30 additions, -5 deletions)

View changed files

📝 packages/better-auth/src/api/routes/callback.ts (+4 -1)
📝 packages/core/src/oauth2/oauth-provider.ts (+1 -1)
📝 packages/core/src/social-providers/github.ts (+25 -3)

📄 Description

Summary by cubic

Surface GitHub OAuth token exchange errors during authorization code validation. This prevents silent failures and maps token exchange failures to a clear invalid_code redirect.

  • Bug Fixes
    • Build the token request with createAuthorizationCodeRequest and call the token endpoint via betterFetch.
    • On fetch errors or GitHub data.error, log and return null; the callback redirects with invalid_code.
    • Update OAuthProvider.validateAuthorizationCode to return OAuth2Tokens | null; successful flows still return tokens via getOAuth2Tokens.

Written for commit 5d9ec3e01e. 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/7186 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 1/7/2026 **Status:** ✅ Merged **Merged:** 1/27/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/github-oauth-data-error-handling` --- ### 📝 Commits (8) - [`785a8b0`](https://github.com/better-auth/better-auth/commit/785a8b0c31594e321c451cc8f790dead4e632c85) fix: handle github data.error - [`655cbd7`](https://github.com/better-auth/better-auth/commit/655cbd770deedb72a7ba1aacf097080c402f20b5) Merge branch 'canary' into fix/github-oauth-data-error-handling - [`020ac7e`](https://github.com/better-auth/better-auth/commit/020ac7e375d13e5cf89d6de3482fdcbf085afa0b) Merge branch 'canary' into fix/github-oauth-data-error-handling - [`af0f82f`](https://github.com/better-auth/better-auth/commit/af0f82f06696c033c90218173c6c803d0664fed0) address comments - [`642a983`](https://github.com/better-auth/better-auth/commit/642a983f2a6aa1efeacf115df3f0c4cbe451a5b6) Merge branch 'canary' into fix/github-oauth-data-error-handling - [`17fc96a`](https://github.com/better-auth/better-auth/commit/17fc96a24aff0414193167e09d6610a64f69d911) Merge branch 'canary' into fix/github-oauth-data-error-handling - [`e4caebf`](https://github.com/better-auth/better-auth/commit/e4caebf5e48a3ad15f06819676326fd0593f3ab2) Merge branch 'canary' into fix/github-oauth-data-error-handling - [`5d9ec3e`](https://github.com/better-auth/better-auth/commit/5d9ec3e01e5da1ee09ce48bd8eac05757b719c63) Merge branch 'canary' into fix/github-oauth-data-error-handling ### 📊 Changes **3 files changed** (+30 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/callback.ts` (+4 -1) 📝 `packages/core/src/oauth2/oauth-provider.ts` (+1 -1) 📝 `packages/core/src/social-providers/github.ts` (+25 -3) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Surface GitHub OAuth token exchange errors during authorization code validation. This prevents silent failures and maps token exchange failures to a clear invalid_code redirect. - **Bug Fixes** - Build the token request with createAuthorizationCodeRequest and call the token endpoint via betterFetch. - On fetch errors or GitHub data.error, log and return null; the callback redirects with invalid_code. - Update OAuthProvider.validateAuthorizationCode to return OAuth2Tokens | null; successful flows still return tokens via getOAuth2Tokens. <sup>Written for commit 5d9ec3e01e5da1ee09ce48bd8eac05757b719c63. 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-03-13 13:25:12 -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#7130