[PR #4951] fix: Generic OAuth and SSO do not work with IDP initiated flows. #22578

Open
opened 2026-04-15 21:08:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4951
Author: @mhornbacher
Created: 9/27/2025
Status: 🔄 Open

Base: mainHead: fix/generic-oauth-blank-states


📝 Commits (4)

  • 064c2e4 fix(generic-oauth): body can be undefined
  • 744f6a5 feat(generic-oauth): enable skipping state validation
  • 1a9cfd4 feat(sso): allow state to be undefined for IDP inititated flows
  • a4b913f Merge branch 'canary' into fix/generic-oauth-blank-states

📊 Changes

3 files changed (+29 additions, -4 deletions)

View changed files

📝 packages/better-auth/src/oauth2/state.ts (+1 -1)
📝 packages/better-auth/src/plugins/generic-oauth/index.ts (+18 -1)
📝 packages/sso/src/index.ts (+10 -2)

📄 Description

Modifies parseState to safely access c.body, which, as the rest of the file suggests, can be undefined. (For context, see https://github.com/better-auth/better-auth/pull/491.)

Additionally, this pull request introduces support for OAuth providers that don’t require a state parameter, enhancing compatibility with providers that initiate the OAuth flow themselves (such as Clever). The changes make the state parameter optional and update the logic to handle cases where it’s not provided. For context here is the clever documentation and I'm sure there are many other provider initiated login flows out there.


Summary by cubic

Fixes a crash in generic OAuth when the request body is undefined and adds support for providers that don’t use the state parameter (e.g., Clever). Improves compatibility and stability across more OAuth providers.

  • Bug Fixes

    • Safely access c.body in parseState using optional chaining to avoid undefined errors.
  • New Features

    • Added stateOptional to GenericOAuthConfig to allow skipping state validation for providers that don’t send state.
    • When stateOptional is enabled and no state is provided, bypass parseState and use safe defaults for the OAuth flow.

🔄 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/4951 **Author:** [@mhornbacher](https://github.com/mhornbacher) **Created:** 9/27/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/generic-oauth-blank-states` --- ### 📝 Commits (4) - [`064c2e4`](https://github.com/better-auth/better-auth/commit/064c2e4a5ef87bfb5f4bb056935cead259924f12) fix(generic-oauth): body can be undefined - [`744f6a5`](https://github.com/better-auth/better-auth/commit/744f6a5c7a27b1ae3856ef61b8791f4191897292) feat(generic-oauth): enable skipping state validation - [`1a9cfd4`](https://github.com/better-auth/better-auth/commit/1a9cfd4f9a9f98c57bc5d4d3a3b9ceddaf827087) feat(sso): allow state to be undefined for IDP inititated flows - [`a4b913f`](https://github.com/better-auth/better-auth/commit/a4b913f1e39c1b82159f0f9b67b7475c18f1dc8c) Merge branch 'canary' into fix/generic-oauth-blank-states ### 📊 Changes **3 files changed** (+29 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/state.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/generic-oauth/index.ts` (+18 -1) 📝 `packages/sso/src/index.ts` (+10 -2) </details> ### 📄 Description Modifies `parseState` to safely access `c.body`, which, as the rest of the file suggests, can be undefined. (For context, see https://github.com/better-auth/better-auth/pull/491.) Additionally, this pull request introduces support for OAuth providers that don’t require a `state` parameter, enhancing compatibility with providers that initiate the OAuth flow themselves (such as Clever). The changes make the `state` parameter optional and update the logic to handle cases where it’s not provided. For context [here is the clever documentation](https://dev.clever.com/docs/oauth-implementation#initiating-logins) and I'm sure there are many other provider initiated login flows out there. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes a crash in generic OAuth when the request body is undefined and adds support for providers that don’t use the state parameter (e.g., Clever). Improves compatibility and stability across more OAuth providers. - **Bug Fixes** - Safely access c.body in parseState using optional chaining to avoid undefined errors. - **New Features** - Added stateOptional to GenericOAuthConfig to allow skipping state validation for providers that don’t send state. - When stateOptional is enabled and no state is provided, bypass parseState and use safe defaults for the OAuth flow. <!-- 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:08:52 -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#22578