[PR #7346] [CLOSED] feat(oauth-provider): add OAuth 2.1 compatible support for optional PKCE #24149

Closed
opened 2026-04-15 22:12:05 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7346
Author: @OscarCornish
Created: 1/14/2026
Status: Closed

Base: canaryHead: fix/maintain-openidconnect-compat-under-oauth2


📝 Commits (4)

  • 52c418f feat(oauth): Allow for disabling PKCE for legacy oidc clients
  • 464632b Merge branch 'canary' into fix/maintain-openidconnect-compat-under-oauth2
  • d98c94c fix comments
  • 3c52936 update docs

📊 Changes

9 files changed (+1139 additions, -45 deletions)

View changed files

📝 docs/content/docs/plugins/oauth-provider.mdx (+92 -3)
📝 packages/oauth-provider/src/authorize.test.ts (+418 -0)
📝 packages/oauth-provider/src/authorize.ts (+46 -13)
📝 packages/oauth-provider/src/metadata.ts (+5 -1)
📝 packages/oauth-provider/src/token.test.ts (+433 -0)
📝 packages/oauth-provider/src/token.ts (+49 -24)
📝 packages/oauth-provider/src/types/index.ts (+36 -1)
📝 packages/oauth-provider/src/types/oauth.ts (+1 -1)
📝 packages/oauth-provider/src/utils/index.ts (+59 -2)

📄 Description

Implements configurable PKCE requirements in the oauth-provider plugin to support OAuth 2.1 compliance while maintaining backward compatibility with legacy confidential clients.

Problem

The new oauth-provider mandates PKCE for all clients, but the older oidc-provider (which supports optional PKCE) will be deprecated. This leaves no migration path for
applications with confidential clients that don't support PKCE.

Solution

Implements a hybrid strategy:

  • Public clients (native, user-agent-based, or public: true) ALWAYS require PKCE (OAuth 2.1 compliant)
  • Confidential clients can opt out of PKCE via requirePKCE: false configuration
  • offline_access scope ALWAYS requires PKCE (even for confidential clients)

Summary by cubic

Make PKCE configurable for confidential clients to keep legacy OIDC apps working, while still enforcing PKCE for public clients and for offline_access. Adds optional support for the plain code challenge and reflects it in OIDC metadata.

  • New Features

    • New options: requirePKCE (default true) and allowPlainCodeChallengeMethod (default false).
    • Authorize: PKCE always for public; confidential respects requirePKCE; offline_access always needs PKCE; validate S256 or plain (when enabled).
    • Token: Public must use PKCE; confidential must use PKCE or client_secret; verify S256/plain when PKCE was used.
    • Metadata: code_challenge_methods_supported includes "plain" when enabled.
  • Migration

    • To support legacy confidential clients without PKCE, set requirePKCE=false (not for public clients).
    • Enable allowPlainCodeChallengeMethod=true only if you must accept plain.

Written for commit 3c5293612d. 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/7346 **Author:** [@OscarCornish](https://github.com/OscarCornish) **Created:** 1/14/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/maintain-openidconnect-compat-under-oauth2` --- ### 📝 Commits (4) - [`52c418f`](https://github.com/better-auth/better-auth/commit/52c418ff4920a03126f2b277e5829ece8592c722) feat(oauth): Allow for disabling PKCE for legacy oidc clients - [`464632b`](https://github.com/better-auth/better-auth/commit/464632b104b99def7589aacaf5415a30d3c215d6) Merge branch 'canary' into fix/maintain-openidconnect-compat-under-oauth2 - [`d98c94c`](https://github.com/better-auth/better-auth/commit/d98c94c97b25452cfad9968de9d6f170dff7f19f) fix comments - [`3c52936`](https://github.com/better-auth/better-auth/commit/3c5293612db92c02608dfccfb9c2d6038989a95f) update docs ### 📊 Changes **9 files changed** (+1139 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/oauth-provider.mdx` (+92 -3) 📝 `packages/oauth-provider/src/authorize.test.ts` (+418 -0) 📝 `packages/oauth-provider/src/authorize.ts` (+46 -13) 📝 `packages/oauth-provider/src/metadata.ts` (+5 -1) 📝 `packages/oauth-provider/src/token.test.ts` (+433 -0) 📝 `packages/oauth-provider/src/token.ts` (+49 -24) 📝 `packages/oauth-provider/src/types/index.ts` (+36 -1) 📝 `packages/oauth-provider/src/types/oauth.ts` (+1 -1) 📝 `packages/oauth-provider/src/utils/index.ts` (+59 -2) </details> ### 📄 Description Implements configurable PKCE requirements in the `oauth-provider` plugin to support OAuth 2.1 compliance while maintaining backward compatibility with legacy confidential clients. ## Problem The new `oauth-provider` mandates PKCE for all clients, but the older `oidc-provider` (which supports optional PKCE) will be deprecated. This leaves no migration path for applications with confidential clients that don't support PKCE. ## Solution Implements a hybrid strategy: - **Public clients** (native, user-agent-based, or `public: true`) ALWAYS require PKCE (OAuth 2.1 compliant) - **Confidential clients** can opt out of PKCE via `requirePKCE: false` configuration - **`offline_access` scope** ALWAYS requires PKCE (even for confidential clients) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Make PKCE configurable for confidential clients to keep legacy OIDC apps working, while still enforcing PKCE for public clients and for offline_access. Adds optional support for the plain code challenge and reflects it in OIDC metadata. - New Features - New options: requirePKCE (default true) and allowPlainCodeChallengeMethod (default false). - Authorize: PKCE always for public; confidential respects requirePKCE; offline_access always needs PKCE; validate S256 or plain (when enabled). - Token: Public must use PKCE; confidential must use PKCE or client_secret; verify S256/plain when PKCE was used. - Metadata: code_challenge_methods_supported includes "plain" when enabled. - Migration - To support legacy confidential clients without PKCE, set requirePKCE=false (not for public clients). - Enable allowPlainCodeChallengeMethod=true only if you must accept plain. <sup>Written for commit 3c5293612db92c02608dfccfb9c2d6038989a95f. 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-15 22:12:05 -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#24149