[PR #3458] [CLOSED] fix(oidc): upgrade to be oauth 2.1 compliant #21735

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3458
Author: @dvanmali
Created: 7/19/2025
Status: Closed

Base: mainHead: oidc


📝 Commits (10+)

  • 9cec79c feat: remote jwks, remote signing, and exportable signing function
  • 27698a2 feat: improved register endpoint will more tests, introduces public client registration type and hardens the confidential client registration process
  • 7e8c119 feat: harden oidc plugin with oAuth2.1 spec to make it prod ready, merges with session schema, utilize jwt plugin for signing, token endpoint supports authorization_code, refresh_token, and client_credentials grants, remove metadata optionto prevent overwrites of required fields, improved scope+claim checking, state returned in errors
  • 0de405c feat: externalize signJwt and createJwk for other plugins
  • 7c24abb fix: mcp correctly utilizes oidc plugin instead of old copy of oidc endpoints, added multiple tests
  • fdfbd9e fix: externalize oidc metadata function, more aud checks, extend OIDCMetadata interface with AuthServerMetadata
  • a231ea7 fix: oauth code requests include RFC 8707 resource parameter to determine audience
  • f1709c5 feat: opaque tokens sent when audience can't be determined from request via resource field
  • 5a80643 style: lint fix
  • 23e50b3 feat: add introspect endpoint

📊 Changes

35 files changed (+7682 additions, -3116 deletions)

View changed files

📝 docs/content/docs/plugins/jwt.mdx (+67 -0)
📝 docs/content/docs/plugins/mcp.mdx (+169 -125)
📝 docs/content/docs/plugins/oidc-provider.mdx (+399 -109)
📝 examples/nextjs-mcp/app/api/echo/route.ts (+17 -4)
📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+3 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+95 -0)
packages/better-auth/src/oauth2/client-credentials-token.ts (+97 -0)
📝 packages/better-auth/src/oauth2/refresh-access-token.ts (+44 -14)
📝 packages/better-auth/src/oauth2/validate-authorization-code.ts (+52 -3)
📝 packages/better-auth/src/plugins/jwt/index.ts (+409 -299)
📝 packages/better-auth/src/plugins/jwt/jwt.test.ts (+210 -36)
packages/better-auth/src/plugins/mcp/authorize.ts (+0 -232)
packages/better-auth/src/plugins/mcp/client.ts (+9 -0)
📝 packages/better-auth/src/plugins/mcp/index.ts (+253 -872)
packages/better-auth/src/plugins/mcp/mcp.test.ts (+364 -0)
packages/better-auth/src/plugins/mcp/metadata.ts (+41 -0)
packages/better-auth/src/plugins/mcp/types.ts (+236 -0)
packages/better-auth/src/plugins/oidc-provider/authorize.test.ts (+176 -0)
📝 packages/better-auth/src/plugins/oidc-provider/authorize.ts (+97 -111)
📝 packages/better-auth/src/plugins/oidc-provider/index.ts (+368 -718)

...and 15 more files

📄 Description

Introduces the following improvements:

OIDC

  • OAuth 2.1 by default
    • Properly supports authorization_code, refresh_token, and client_credentials grants
    • PKCE by default (removes plain completely)
  • JWT verifiable by JWKS through JWT Plugin
  • Consolidation of Refresh Token onto Session
  • oauthAccessToken strictly deals with opaque tokens
    • Opaque tokens are given only when resource parameter (aka audience) is not provided
  • Option to Encode and Decode refresh tokens
  • allowDynamicClientRegistration with allowUnauthenticatedClientRegistration flags
  • Separation of default expiration times
  • Proper creation of public and confidential clients
  • Prevents misconfiguration between .well-known/openid-configuration endpoint and plugin settings
  • Tests Files: 7, Tests: 54

JWT

  • Remote signing
  • Remote JWKS
  • Compatibility with OIDC (removes /token endpoint)
  • Tests: 14

MCP

  • Separates MCP logic from authentication logic. OIDC package handles the Auth 2.1 server (ie OIDC just uses "openid" scope)
  • checkMcp function to support more platforms beyond react
  • oAuthDiscoveryMetadata endpoint is configurable per endpoint and is hosted by the resource server instead of the authorization server.
  • Tests: 9

Summary by cubic

Upgraded the OIDC implementation to be OAuth 2.1 compliant, adding support for authorization_code, refresh_token, and client_credentials grants, PKCE by default, dynamic client registration, and improved JWT handling. The MCP and JWT plugins were updated for better OIDC compatibility, remote JWKS, and clearer separation of authentication logic.

  • New Features

    • OAuth 2.1 compliance with PKCE required and no plain method.
    • Dynamic and unauthenticated client registration options.
    • Support for opaque tokens when no audience is provided.
    • Remote JWKS and remote signing support in JWT plugin.
    • New endpoints: introspect and revoke for token management.
    • Improved public/confidential client handling and error reporting.
  • Refactors

    • MCP plugin now delegates OAuth logic to the OIDC provider for consistency.
    • Session and refresh token logic consolidated.
    • Codebase reorganized for clearer separation between authentication and resource server logic.

🔄 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/3458 **Author:** [@dvanmali](https://github.com/dvanmali) **Created:** 7/19/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `oidc` --- ### 📝 Commits (10+) - [`9cec79c`](https://github.com/better-auth/better-auth/commit/9cec79cdd00e01ad49de4b80266b901bf193605f) feat: remote jwks, remote signing, and exportable signing function - [`27698a2`](https://github.com/better-auth/better-auth/commit/27698a2c9f6edc3567e65944728208e5ebba025d) feat: improved register endpoint will more tests, introduces public client registration type and hardens the confidential client registration process - [`7e8c119`](https://github.com/better-auth/better-auth/commit/7e8c1199340b83711a9ea4b950bf6f0da46e5ace) feat: harden oidc plugin with oAuth2.1 spec to make it prod ready, merges with session schema, utilize jwt plugin for signing, token endpoint supports authorization_code, refresh_token, and client_credentials grants, remove metadata optionto prevent overwrites of required fields, improved scope+claim checking, state returned in errors - [`0de405c`](https://github.com/better-auth/better-auth/commit/0de405cf7412088266626142519c92c183d602a0) feat: externalize signJwt and createJwk for other plugins - [`7c24abb`](https://github.com/better-auth/better-auth/commit/7c24abbd3da34794634d2abbe962c355c1a5e903) fix: mcp correctly utilizes oidc plugin instead of old copy of oidc endpoints, added multiple tests - [`fdfbd9e`](https://github.com/better-auth/better-auth/commit/fdfbd9eeeb98000258a12dc1ca2ad655a2418cee) fix: externalize oidc metadata function, more aud checks, extend OIDCMetadata interface with AuthServerMetadata - [`a231ea7`](https://github.com/better-auth/better-auth/commit/a231ea7f267254aaf031ee3b5038f5df85e44915) fix: oauth code requests include RFC 8707 resource parameter to determine audience - [`f1709c5`](https://github.com/better-auth/better-auth/commit/f1709c538d8f052495477ab7b183ff88d683ca09) feat: opaque tokens sent when audience can't be determined from request via resource field - [`5a80643`](https://github.com/better-auth/better-auth/commit/5a80643cf8d6f6abe43242dc4e165d900001781c) style: lint fix - [`23e50b3`](https://github.com/better-auth/better-auth/commit/23e50b31b49ed97f6d4ced6b694990dc823e5141) feat: add introspect endpoint ### 📊 Changes **35 files changed** (+7682 additions, -3116 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/jwt.mdx` (+67 -0) 📝 `docs/content/docs/plugins/mcp.mdx` (+169 -125) 📝 `docs/content/docs/plugins/oidc-provider.mdx` (+399 -109) 📝 `examples/nextjs-mcp/app/api/echo/route.ts` (+17 -4) 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+3 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+95 -0) ➕ `packages/better-auth/src/oauth2/client-credentials-token.ts` (+97 -0) 📝 `packages/better-auth/src/oauth2/refresh-access-token.ts` (+44 -14) 📝 `packages/better-auth/src/oauth2/validate-authorization-code.ts` (+52 -3) 📝 `packages/better-auth/src/plugins/jwt/index.ts` (+409 -299) 📝 `packages/better-auth/src/plugins/jwt/jwt.test.ts` (+210 -36) ➖ `packages/better-auth/src/plugins/mcp/authorize.ts` (+0 -232) ➕ `packages/better-auth/src/plugins/mcp/client.ts` (+9 -0) 📝 `packages/better-auth/src/plugins/mcp/index.ts` (+253 -872) ➕ `packages/better-auth/src/plugins/mcp/mcp.test.ts` (+364 -0) ➕ `packages/better-auth/src/plugins/mcp/metadata.ts` (+41 -0) ➕ `packages/better-auth/src/plugins/mcp/types.ts` (+236 -0) ➕ `packages/better-auth/src/plugins/oidc-provider/authorize.test.ts` (+176 -0) 📝 `packages/better-auth/src/plugins/oidc-provider/authorize.ts` (+97 -111) 📝 `packages/better-auth/src/plugins/oidc-provider/index.ts` (+368 -718) _...and 15 more files_ </details> ### 📄 Description **Introduces the following improvements:** ## OIDC - OAuth 2.1 by default - Properly supports authorization_code, refresh_token, and client_credentials grants - PKCE by default (removes `plain` completely) - JWT verifiable by JWKS through JWT Plugin - Consolidation of Refresh Token onto Session - `oauthAccessToken` strictly deals with opaque tokens - Opaque tokens are given only when resource parameter (aka audience) is not provided - Option to Encode and Decode refresh tokens - `allowDynamicClientRegistration` with `allowUnauthenticatedClientRegistration` flags - Separation of default expiration times - Proper creation of public and confidential clients - Prevents misconfiguration between `.well-known/openid-configuration` endpoint and plugin settings - Tests Files: 7, Tests: 54 ## JWT - Remote signing - Remote JWKS - Compatibility with OIDC (removes /token endpoint) - Tests: 14 ## MCP - Separates MCP logic from authentication logic. OIDC package handles the Auth 2.1 server (ie OIDC just uses "openid" scope) - `checkMcp` function to support more platforms beyond react - `oAuthDiscoveryMetadata` endpoint is configurable per endpoint and is hosted by the resource server instead of the authorization server. - Tests: 9 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Upgraded the OIDC implementation to be OAuth 2.1 compliant, adding support for authorization_code, refresh_token, and client_credentials grants, PKCE by default, dynamic client registration, and improved JWT handling. The MCP and JWT plugins were updated for better OIDC compatibility, remote JWKS, and clearer separation of authentication logic. - **New Features** - OAuth 2.1 compliance with PKCE required and no plain method. - Dynamic and unauthenticated client registration options. - Support for opaque tokens when no audience is provided. - Remote JWKS and remote signing support in JWT plugin. - New endpoints: introspect and revoke for token management. - Improved public/confidential client handling and error reporting. - **Refactors** - MCP plugin now delegates OAuth logic to the OIDC provider for consistency. - Session and refresh token logic consolidated. - Codebase reorganized for clearer separation between authentication and resource server logic. <!-- 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 20:34:01 -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#21735