[PR #4727] [CLOSED] Fix generic OAuth discovery when providers skip JSON headers #22452

Closed
opened 2026-04-15 21:03:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4727
Author: @Karavil
Created: 9/17/2025
Status: Closed

Base: canaryHead: fix/generic-oauth-discovery-fallback


📝 Commits (1)

  • 380340b fix: tolerate non-json oauth discovery

📊 Changes

2 files changed (+192 additions, -48 deletions)

View changed files

📝 packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts (+82 -1)
📝 packages/better-auth/src/plugins/generic-oauth/index.ts (+110 -47)

📄 Description

Fixes generic OAuth discovery to handle non-compliant providers like Clever that return 200 status with incorrect Content-Type headers.

Problem: Clever's discovery endpoint returns application/x-www-form-urlencoded instead of application/json, causing betterFetch to return a Blob and breaking the plugin with INVALID_OAUTH_CONFIGURATION.

Solution: Replace betterFetch with a robust fetchDiscoveryDocument helper that:

  • Uses bare fetch to avoid content-type assumptions
  • Validates responses with Zod schema
  • Logs RFC 8414 §3.1 warnings but continues with best-effort parsing
  • Maintains the same { data, error } API shape for backward compatibility

Testing: Added test coverage for both compliant providers and Clever's non-compliant response format using a lightweight discovery server helper.

Compliant providers work exactly as before, while non-compliant ones now succeed without requiring hardcoded endpoints in downstream apps.


🔄 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/4727 **Author:** [@Karavil](https://github.com/Karavil) **Created:** 9/17/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/generic-oauth-discovery-fallback` --- ### 📝 Commits (1) - [`380340b`](https://github.com/better-auth/better-auth/commit/380340b4f63b0f6d63790ac949d298de2ea7c0e1) fix: tolerate non-json oauth discovery ### 📊 Changes **2 files changed** (+192 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts` (+82 -1) 📝 `packages/better-auth/src/plugins/generic-oauth/index.ts` (+110 -47) </details> ### 📄 Description Fixes generic OAuth discovery to handle non-compliant providers like Clever that return 200 status with incorrect Content-Type headers. **Problem**: Clever's discovery endpoint returns `application/x-www-form-urlencoded` instead of `application/json`, causing betterFetch to return a Blob and breaking the plugin with INVALID_OAUTH_CONFIGURATION. **Solution**: Replace betterFetch with a robust fetchDiscoveryDocument helper that: - Uses bare fetch to avoid content-type assumptions - Validates responses with Zod schema - Logs RFC 8414 §3.1 warnings but continues with best-effort parsing - Maintains the same `{ data, error }` API shape for backward compatibility **Testing**: Added test coverage for both compliant providers and Clever's non-compliant response format using a lightweight discovery server helper. Compliant providers work exactly as before, while non-compliant ones now succeed without requiring hardcoded endpoints in downstream apps. --- <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-15 21:03:34 -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#22452