[PR #6652] [MERGED] Unify SSO/OAuth account linking and add domain-based org assignment to all sign-in flows #15051

Closed
opened 2026-04-13 09:47:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6652
Author: @Paola3stefania
Created: 12/10/2025
Status: Merged
Merged: 12/16/2025
Merged by: @Bekacru

Base: canaryHead: feat/unify-sso-linking


📝 Commits (10+)

  • 9c677c6 feat(sso): add NormalizedSSOProfile type and profile mapping helpers
  • 444230d make lint happy
  • f3c8af8 feat: extract unified organization assignment functions
  • 93a418e refactor: use handleOAuthUserInfo in callbackSSOSAML
  • 747385a fix: SAML ACS now respects disableImplicitSignUp option
  • 8d224cb refactor: use assignOrganizationFromProvider in OIDC callback
  • 6dfbba8 feat: auto-assign org membership on social OAuth by email domain
  • 5e007ae feat: tests
  • 304fa06 remove previous implementation
  • 4a8f4d0 fix schema

📊 Changes

6 files changed (+398 additions, -257 deletions)

View changed files

📝 packages/sso/src/index.ts (+29 -0)
packages/sso/src/linking/index.ts (+2 -0)
packages/sso/src/linking/org-assignment.ts (+176 -0)
packages/sso/src/linking/types.ts (+10 -0)
📝 packages/sso/src/routes/sso.ts (+105 -242)
📝 packages/sso/src/saml.test.ts (+76 -15)

📄 Description

This PR refactors SSO flows (SAML and OIDC) to use the shared handleOAuthUserInfo() pipeline, ensuring consistent identity linking, signup behavior, and organization assignment across all protocols.

Bug Fix

SAML ACS (IdP-initiated) ignored disableImplicitSignUp
Users were created even when implicit sign-up was disabled.
This is now fixed by routing SAML callbacks through the unified linking pipeline.

Breaking Change

SSO errors now follow standard redirect-based protocol behavior:

Before:
HTTP 401 UNAUTHORIZED thrown when disableImplicitSignUp was enabled and the user did not exist.

After:
A 302 redirect occurs with ?error=signup_disabled in the callback URL.

This aligns with how SAML and OIDC flows expect error handling and prevents breaking the browser redirect chain.


fixes https://github.com/better-auth/better-auth/issues/4972


🔄 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/6652 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 12/10/2025 **Status:** ✅ Merged **Merged:** 12/16/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/unify-sso-linking` --- ### 📝 Commits (10+) - [`9c677c6`](https://github.com/better-auth/better-auth/commit/9c677c69d9627f46c895db4b53878817a971deaa) feat(sso): add NormalizedSSOProfile type and profile mapping helpers - [`444230d`](https://github.com/better-auth/better-auth/commit/444230d870d1768c744ffafa19b36b8bd963ee54) make lint happy - [`f3c8af8`](https://github.com/better-auth/better-auth/commit/f3c8af812a36d833d015ca9d64de12c43ed83ace) feat: extract unified organization assignment functions - [`93a418e`](https://github.com/better-auth/better-auth/commit/93a418e0e2441e06dbaa84478c32c9e220c54b46) refactor: use handleOAuthUserInfo in callbackSSOSAML - [`747385a`](https://github.com/better-auth/better-auth/commit/747385ac98d0b44d8c4756832cadb0bcd85024fc) fix: SAML ACS now respects disableImplicitSignUp option - [`8d224cb`](https://github.com/better-auth/better-auth/commit/8d224cbe4542b48e5edffc58ccbae671037f4064) refactor: use assignOrganizationFromProvider in OIDC callback - [`6dfbba8`](https://github.com/better-auth/better-auth/commit/6dfbba8a2be4c83d3f75a0a49402f8647325d7a6) feat: auto-assign org membership on social OAuth by email domain - [`5e007ae`](https://github.com/better-auth/better-auth/commit/5e007ae1a44df22b19a9ffc19e46d7a7f13fe141) feat: tests - [`304fa06`](https://github.com/better-auth/better-auth/commit/304fa060f78e04b927cf8024e356b75ad9af0f79) remove previous implementation - [`4a8f4d0`](https://github.com/better-auth/better-auth/commit/4a8f4d0e8167975d486c2ddcae2b4a0116396233) fix schema ### 📊 Changes **6 files changed** (+398 additions, -257 deletions) <details> <summary>View changed files</summary> 📝 `packages/sso/src/index.ts` (+29 -0) ➕ `packages/sso/src/linking/index.ts` (+2 -0) ➕ `packages/sso/src/linking/org-assignment.ts` (+176 -0) ➕ `packages/sso/src/linking/types.ts` (+10 -0) 📝 `packages/sso/src/routes/sso.ts` (+105 -242) 📝 `packages/sso/src/saml.test.ts` (+76 -15) </details> ### 📄 Description This PR refactors SSO flows (SAML and OIDC) to use the shared `handleOAuthUserInfo()` pipeline, ensuring consistent identity linking, signup behavior, and organization assignment across all protocols. ## Bug Fix **SAML ACS (IdP-initiated) ignored `disableImplicitSignUp`** Users were created even when implicit sign-up was disabled. This is now fixed by routing SAML callbacks through the unified linking pipeline. ## Breaking Change SSO errors now follow standard redirect-based protocol behavior: **Before:** `HTTP 401 UNAUTHORIZED` thrown when `disableImplicitSignUp` was enabled and the user did not exist. **After:** A `302` redirect occurs with `?error=signup_disabled` in the callback URL. This aligns with how SAML and OIDC flows expect error handling and prevents breaking the browser redirect chain. --------- fixes https://github.com/better-auth/better-auth/issues/4972 --- <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-13 09:47:53 -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#15051