[PR #6395] [MERGED] feat(sso): add OIDC discovery #23538

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6395
Author: @Paola3stefania
Created: 11/28/2025
Status: Merged
Merged: 12/12/2025
Merged by: @Bekacru

Base: canaryHead: feat/sso-oidc-discovery


📝 Commits (10+)

  • 5762d8b feat(sso): add OIDC discovery pipeline module
  • 5d4b8a2 code challenge fix
  • 115f742 improve docu
  • 16a4f25 fix: just methods supported
  • 5cab5af fix: communicate methods out of scope
  • ffb99e6 feat: add more test and clear comments
  • 9863888 Merge branch 'canary' into feat/sso-oidc-discovery
  • b1d7450 fix: lint
  • ec42bd0 Merge branch 'canary' into feat/sso-oidc-discovery
  • cf11cbf fix: use timout betterfetch built in

📊 Changes

10 files changed (+1788 additions, -243 deletions)

View changed files

📝 docs/content/docs/plugins/sso.mdx (+111 -0)
📝 packages/sso/src/index.ts (+19 -0)
📝 packages/sso/src/oidc.test.ts (+0 -164)
packages/sso/src/oidc/discovery.test.ts (+823 -0)
packages/sso/src/oidc/discovery.ts (+355 -0)
packages/sso/src/oidc/errors.ts (+86 -0)
packages/sso/src/oidc/index.ts (+31 -0)
packages/sso/src/oidc/types.ts (+210 -0)
📝 packages/sso/src/routes/sso.ts (+88 -23)
📝 packages/sso/src/saml.test.ts (+65 -56)

📄 Description

Add new discovery module for fetching and validating OIDC configuration from .well-known/openid-configuration endpoints.


Summary by cubic

Add OIDC discovery to SSO to fetch, validate, and hydrate provider config from .well-known/openid-configuration. This simplifies provider setup with registration-time validation and enables runtime discovery for legacy configs.

  • New Features
    • discoverOIDCConfig: computes the discovery URL, fetches the document, validates issuer and required fields, selects token auth, and returns a hydrated config (existing values take precedence).
    • Structured errors via DiscoveryError codes mapped to API errors during registration: discovery_timeout, discovery_not_found, discovery_invalid_url, discovery_invalid_json, issuer_mismatch, discovery_incomplete, unsupported_token_auth_method, discovery_unexpected_error.
    • Token endpoint auth selection with sensible defaults (prefers client_secret_basic; supports client_secret_post if advertised).
    • needsRuntimeDiscovery helper to trigger discovery when token/jwks endpoints are missing.
    • Integrated into registerSSOProvider: performs discovery at registration, hydrates endpoints, and fails fast on misconfigured IdPs (user overrides win).
    • 10s default timeout using betterFetch’s built-in timeout, plus comprehensive tests for success and failure cases.
    • New skipDiscovery option on registerSSOProvider to bypass discovery and require manual endpoints when needed.

Written for commit e6bcb4408b. 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/6395 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 11/28/2025 **Status:** ✅ Merged **Merged:** 12/12/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/sso-oidc-discovery` --- ### 📝 Commits (10+) - [`5762d8b`](https://github.com/better-auth/better-auth/commit/5762d8b769d265510c9defe9bc2cdfbfc9ea8715) feat(sso): add OIDC discovery pipeline module - [`5d4b8a2`](https://github.com/better-auth/better-auth/commit/5d4b8a2b62c13f576770164afbd880e0e5bab430) code challenge fix - [`115f742`](https://github.com/better-auth/better-auth/commit/115f7427ee5ff4fd1893eeef61d3ceedd8fa0a74) improve docu - [`16a4f25`](https://github.com/better-auth/better-auth/commit/16a4f25d8871e1e40f843c7b16675e70e05bd949) fix: just methods supported - [`5cab5af`](https://github.com/better-auth/better-auth/commit/5cab5af9096ace10df2e59ced6b8b37bf9f34a92) fix: communicate methods out of scope - [`ffb99e6`](https://github.com/better-auth/better-auth/commit/ffb99e6f21358be096a22370da03df57f486f3cc) feat: add more test and clear comments - [`9863888`](https://github.com/better-auth/better-auth/commit/9863888be9c1d4e4d4a20cfac2c8533dadf2ec4a) Merge branch 'canary' into feat/sso-oidc-discovery - [`b1d7450`](https://github.com/better-auth/better-auth/commit/b1d7450803a7e55e7efa0c6ebad2f34e1d9e9bd1) fix: lint - [`ec42bd0`](https://github.com/better-auth/better-auth/commit/ec42bd05bc87b64ee9d715688b51f60fd8d3b7a4) Merge branch 'canary' into feat/sso-oidc-discovery - [`cf11cbf`](https://github.com/better-auth/better-auth/commit/cf11cbfa6b4919f957f58870250d59e5ab562737) fix: use timout betterfetch built in ### 📊 Changes **10 files changed** (+1788 additions, -243 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/sso.mdx` (+111 -0) 📝 `packages/sso/src/index.ts` (+19 -0) 📝 `packages/sso/src/oidc.test.ts` (+0 -164) ➕ `packages/sso/src/oidc/discovery.test.ts` (+823 -0) ➕ `packages/sso/src/oidc/discovery.ts` (+355 -0) ➕ `packages/sso/src/oidc/errors.ts` (+86 -0) ➕ `packages/sso/src/oidc/index.ts` (+31 -0) ➕ `packages/sso/src/oidc/types.ts` (+210 -0) 📝 `packages/sso/src/routes/sso.ts` (+88 -23) 📝 `packages/sso/src/saml.test.ts` (+65 -56) </details> ### 📄 Description Add new discovery module for fetching and validating OIDC configuration from .well-known/openid-configuration endpoints. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add OIDC discovery to SSO to fetch, validate, and hydrate provider config from .well-known/openid-configuration. This simplifies provider setup with registration-time validation and enables runtime discovery for legacy configs. - **New Features** - discoverOIDCConfig: computes the discovery URL, fetches the document, validates issuer and required fields, selects token auth, and returns a hydrated config (existing values take precedence). - Structured errors via DiscoveryError codes mapped to API errors during registration: discovery_timeout, discovery_not_found, discovery_invalid_url, discovery_invalid_json, issuer_mismatch, discovery_incomplete, unsupported_token_auth_method, discovery_unexpected_error. - Token endpoint auth selection with sensible defaults (prefers client_secret_basic; supports client_secret_post if advertised). - needsRuntimeDiscovery helper to trigger discovery when token/jwks endpoints are missing. - Integrated into registerSSOProvider: performs discovery at registration, hydrates endpoints, and fails fast on misconfigured IdPs (user overrides win). - 10s default timeout using betterFetch’s built-in timeout, plus comprehensive tests for success and failure cases. - New skipDiscovery option on registerSSOProvider to bypass discovery and require manual endpoints when needed. <sup>Written for commit e6bcb4408b64296c6d22e4442ddcf607128b92b1. 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-15 21:48:22 -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#23538