[PR #6179] [MERGED] feat(generic-oauth): add custom token exchange support for non-standard providers #14752

Closed
opened 2026-04-13 09:37:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6179
Author: @bytaesu
Created: 11/21/2025
Status: Merged
Merged: 11/22/2025
Merged by: @Bekacru

Base: canaryHead: 2025-11-22/feat/oauth-custom-token-exchange


📝 Commits (10+)

  • 363903f feat(generic-oauth): add custom token exchange support for non-standard providers
  • 468172d fix: type from any to unknown
  • 11cf73b cleanup comment
  • 7256adb test: adjust test cases for non-standard provider
  • 10c31bc docs: update content about custom token exchange
  • 88f3c7c fix: lint
  • 32b2636 docs: clearer description
  • 1ec6930 fix: restore tokenUrlParams support in callback
  • 8e2af38 Update docs/content/docs/plugins/generic-oauth.mdx
  • b2cba52 refactor: error codes management

📊 Changes

7 files changed (+459 additions, -58 deletions)

View changed files

📝 docs/content/docs/plugins/generic-oauth.mdx (+83 -0)
📝 packages/better-auth/src/adapters/kysely-adapter/dialect.ts (+1 -1)
packages/better-auth/src/plugins/generic-oauth/error-codes.ts (+10 -0)
📝 packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts (+275 -0)
📝 packages/better-auth/src/plugins/generic-oauth/index.ts (+83 -57)
📝 packages/core/src/oauth2/oauth-provider.ts (+5 -0)
📝 packages/core/src/oauth2/utils.ts (+2 -0)

📄 Description

Summary by cubic

Add custom token exchange support to generic-oauth for non‑standard providers and preserve raw token responses. This enables integrations with providers that use GET token endpoints or custom params without breaking existing flows.

  • New Features

    • Added config.getToken to genericOAuth to override the code→token exchange (supports GET endpoints, PKCE, custom params).
    • OAuth2Tokens now includes raw; getOAuth2Tokens preserves the full provider payload.
    • Callback uses config.getToken when provided, then falls back to the standard validateAuthorizationCode flow.
  • Bug Fixes

    • Restored tokenUrlParams support in the callback.
    • Removed unused SqliteDatabase import, centralized error codes, and minor type/lint cleanups.

Written for commit b2cba52e03. Summary will update automatically 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/6179 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 11/21/2025 **Status:** ✅ Merged **Merged:** 11/22/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `2025-11-22/feat/oauth-custom-token-exchange` --- ### 📝 Commits (10+) - [`363903f`](https://github.com/better-auth/better-auth/commit/363903f57176926d86dbbd6fcee333a982cb14da) feat(generic-oauth): add custom token exchange support for non-standard providers - [`468172d`](https://github.com/better-auth/better-auth/commit/468172d748739506920e067880181b7b9eb0722f) fix: type from any to unknown - [`11cf73b`](https://github.com/better-auth/better-auth/commit/11cf73b766427a2afe31f345f7c7a938cb00d902) cleanup comment - [`7256adb`](https://github.com/better-auth/better-auth/commit/7256adbeeaba6abfa2fd087baf88c20fc0a664e4) test: adjust test cases for non-standard provider - [`10c31bc`](https://github.com/better-auth/better-auth/commit/10c31bc2036febaecaf37c7e8f5bcf61b3f7b65b) docs: update content about custom token exchange - [`88f3c7c`](https://github.com/better-auth/better-auth/commit/88f3c7c36eaf196d2609aae02f6458c1bfcd3cdb) fix: lint - [`32b2636`](https://github.com/better-auth/better-auth/commit/32b2636303548086e22c179992703e0d47bf5274) docs: clearer description - [`1ec6930`](https://github.com/better-auth/better-auth/commit/1ec6930056e7d9558be762e3e757d1b0b236c008) fix: restore tokenUrlParams support in callback - [`8e2af38`](https://github.com/better-auth/better-auth/commit/8e2af389850300669170b9f6f15af166bb0c1363) Update docs/content/docs/plugins/generic-oauth.mdx - [`b2cba52`](https://github.com/better-auth/better-auth/commit/b2cba52e0325c918a1d986ca36cd2ff6a7ad2b40) refactor: error codes management ### 📊 Changes **7 files changed** (+459 additions, -58 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/generic-oauth.mdx` (+83 -0) 📝 `packages/better-auth/src/adapters/kysely-adapter/dialect.ts` (+1 -1) ➕ `packages/better-auth/src/plugins/generic-oauth/error-codes.ts` (+10 -0) 📝 `packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts` (+275 -0) 📝 `packages/better-auth/src/plugins/generic-oauth/index.ts` (+83 -57) 📝 `packages/core/src/oauth2/oauth-provider.ts` (+5 -0) 📝 `packages/core/src/oauth2/utils.ts` (+2 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Add custom token exchange support to generic-oauth for non‑standard providers and preserve raw token responses. This enables integrations with providers that use GET token endpoints or custom params without breaking existing flows. - **New Features** - Added config.getToken to genericOAuth to override the code→token exchange (supports GET endpoints, PKCE, custom params). - OAuth2Tokens now includes raw; getOAuth2Tokens preserves the full provider payload. - Callback uses config.getToken when provided, then falls back to the standard validateAuthorizationCode flow. - **Bug Fixes** - Restored tokenUrlParams support in the callback. - Removed unused SqliteDatabase import, centralized error codes, and minor type/lint cleanups. <sup>Written for commit b2cba52e0325c918a1d986ca36cd2ff6a7ad2b40. Summary will update automatically 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 09:37:17 -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#14752