[PR #7335] [CLOSED] fix(sso): support multi-domain providers in account linking #7238

Closed
opened 2026-03-13 13:29:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7335
Author: @thewh1teagle
Created: 1/13/2026
Status: Closed

Base: canaryHead: fix/sso-multi-domain-provider-lookup


📝 Commits (1)

  • 151e8d3 fix(sso): support multi-domain providers in account linking

📊 Changes

1 file changed (+65 additions, -15 deletions)

View changed files

📝 packages/sso/src/routes/sso.ts (+65 -15)

📄 Description

Summary

Fixes

When multiple domains are registered for the same SSO providerId (e.g., domain1.com and domain2.com sharing one Okta provider), account linking would fail with account_not_linked errors for users from secondary domains.

Problem

The issue occurs because domain validation only checks against a single provider row returned by findOne, even when multiple domains exist for the same providerId. This is common in enterprise scenarios where one IdP (like Okta) serves multiple email domains.

Solution

  • Added validateEmailDomainForProvider() to check email domain against all provider domains for a given providerId
  • Extracted trust validation logic into isProviderTrusted() helper for better readability
  • Updated both SAML callback endpoints to use the new multi-domain validation

Changes

  • Query all provider rows with findMany when validating domain
  • Check if user email matches any of the registered domains
  • Maintains backward compatibility for single-domain providers

Testing

Tested manually with multi-domain Okta setup.

Backward Compatibility

Single-domain providers continue to work identically (array with 1 item)
No breaking changes to API or behavior


🔄 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/7335 **Author:** [@thewh1teagle](https://github.com/thewh1teagle) **Created:** 1/13/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/sso-multi-domain-provider-lookup` --- ### 📝 Commits (1) - [`151e8d3`](https://github.com/better-auth/better-auth/commit/151e8d3260eba45219785a9284a74bbd466f89b0) fix(sso): support multi-domain providers in account linking ### 📊 Changes **1 file changed** (+65 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `packages/sso/src/routes/sso.ts` (+65 -15) </details> ### 📄 Description ## Summary Fixes - #7324 When multiple domains are registered for the same SSO `providerId` (e.g., `domain1.com` and `domain2.com` sharing one Okta provider), account linking would fail with `account_not_linked` errors for users from secondary domains. ## Problem The issue occurs because domain validation only checks against a single provider row returned by `findOne`, even when multiple domains exist for the same `providerId`. This is common in enterprise scenarios where one IdP (like Okta) serves multiple email domains. ## Solution - Added `validateEmailDomainForProvider()` to check email domain against **all** provider domains for a given `providerId` - Extracted trust validation logic into `isProviderTrusted()` helper for better readability - Updated both SAML callback endpoints to use the new multi-domain validation ## Changes - Query all provider rows with `findMany` when validating domain - Check if user email matches **any** of the registered domains - Maintains backward compatibility for single-domain providers ## Testing Tested manually with multi-domain Okta setup. ## Backward Compatibility ✅ Single-domain providers continue to work identically (array with 1 item) ✅ No breaking changes to API or behavior --- <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-03-13 13:29:19 -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#7238