[PR #7708] [MERGED] fix(sso): correct IdentityProvider configuration in signInSSO #15751

Closed
opened 2026-04-13 10:12:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7708
Author: @theNailz
Created: 1/30/2026
Status: Merged
Merged: 2/5/2026
Merged by: @himself65

Base: canaryHead: canary


📝 Commits (2)

  • cc408fc fix(sso): correct IdentityProvider configuration in signInSSO
  • c8ddaf5 Merge branch 'canary' into canary

📊 Changes

2 files changed (+119 additions, -9 deletions)

View changed files

📝 packages/sso/src/routes/sso.ts (+30 -9)
📝 packages/sso/src/saml.test.ts (+89 -0)

📄 Description

Problem

The signInSSO endpoint incorrectly constructs the samlify IdentityProvider, causing:

  • Azure AD (and other IdPs) to reject the SAML AuthnRequest with:
    AADSTS7500511: XML attribute 'AssertionConsumerServiceURL' in the SAML message must be a URI

Root Cause

In signInSSO, the IdentityProvider was constructed with:

  1. Wrong field name: encryptCert instead of signingCert - samlify ignores encryptCert for signing
  2. Missing fallback: entityID doesn't fall back to parsedSamlConfig.issuer
  3. Missing fallback: singleSignOnService doesn't fall back to idpData?.singleSignOnService or parsedSamlConfig.entryPoint
  4. Wrong config: wantAuthnRequestsSigned used wantAssertionsSigned instead of authnRequestsSigned

The callbackSSOSAML endpoint had similar inconsistencies (items 3 & 4).

Solution

Align the signInSSO and callbackSSOSAML implementations by:

  1. Using signingCert instead of encryptCert
  2. Adding fallback to parsedSamlConfig.issuer for entityID
  3. Adding fallback to idpData?.singleSignOnService then parsedSamlConfig.entryPoint for singleSignOnService
  4. Using authnRequestsSigned for wantAuthnRequestsSigned - this must match the SP's authnRequestsSigned flag or samlify throws ERR_METADATA_CONFLICT_REQUEST_SIGNED_FLAG
  5. Handling both metadata and non-metadata IdP configurations
  6. Including privateKey/privateKeyPass in the metadata branch

Testing

  • Added test suite for SAML SSO with idpMetadata but without metadata XML
  • All 84 SAML tests pass
  • pnpm lint, pnpm typecheck pass

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com


🔄 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/7708 **Author:** [@theNailz](https://github.com/theNailz) **Created:** 1/30/2026 **Status:** ✅ Merged **Merged:** 2/5/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `canary` --- ### 📝 Commits (2) - [`cc408fc`](https://github.com/better-auth/better-auth/commit/cc408fcbd9b4b300d8848642a502ef981416c4cb) fix(sso): correct IdentityProvider configuration in signInSSO - [`c8ddaf5`](https://github.com/better-auth/better-auth/commit/c8ddaf55a955a214f3055ae5fe0c7ded34d4592a) Merge branch 'canary' into canary ### 📊 Changes **2 files changed** (+119 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/sso/src/routes/sso.ts` (+30 -9) 📝 `packages/sso/src/saml.test.ts` (+89 -0) </details> ### 📄 Description ## Problem The `signInSSO` endpoint incorrectly constructs the samlify `IdentityProvider`, causing: - Azure AD (and other IdPs) to reject the SAML AuthnRequest with: `AADSTS7500511: XML attribute 'AssertionConsumerServiceURL' in the SAML message must be a URI` ## Root Cause In `signInSSO`, the `IdentityProvider` was constructed with: 1. Wrong field name: `encryptCert` instead of `signingCert` - samlify ignores `encryptCert` for signing 2. Missing fallback: `entityID` doesn't fall back to `parsedSamlConfig.issuer` 3. Missing fallback: `singleSignOnService` doesn't fall back to `idpData?.singleSignOnService` or `parsedSamlConfig.entryPoint` 4. Wrong config: `wantAuthnRequestsSigned` used `wantAssertionsSigned` instead of `authnRequestsSigned` The `callbackSSOSAML` endpoint had similar inconsistencies (items 3 & 4). ## Solution Align the `signInSSO` and `callbackSSOSAML` implementations by: 1. Using `signingCert` instead of `encryptCert` 2. Adding fallback to `parsedSamlConfig.issuer` for `entityID` 3. Adding fallback to `idpData?.singleSignOnService` then `parsedSamlConfig.entryPoint` for `singleSignOnService` 4. **Using `authnRequestsSigned` for `wantAuthnRequestsSigned`** - this must match the SP's `authnRequestsSigned` flag or samlify throws `ERR_METADATA_CONFLICT_REQUEST_SIGNED_FLAG` 5. Handling both metadata and non-metadata IdP configurations 6. Including `privateKey`/`privateKeyPass` in the metadata branch ## Testing - Added test suite for SAML SSO with idpMetadata but without metadata XML - All 84 SAML tests pass - `pnpm lint`, `pnpm typecheck` pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --- <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 10:12:28 -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#15751