LibreChat/api/strategies
Danny Avila 4f37e8adb9
🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472)
* refactor: Add existingUsersOnly support to social and SAML auth callbacks

- Add `existingUsersOnly` option to the `socialLogin` handler factory to
  reject unknown users instead of creating new accounts
- Refactor SAML strategy callback into `createSamlCallback(existingUsersOnly)`
  factory function, mirroring the OpenID `createOpenIDCallback` pattern
- Extract shared SAML config into `getBaseSamlConfig()` helper
- Register `samlAdmin` passport strategy with `existingUsersOnly: true` and
  admin-specific callback URL, called automatically from `setupSaml()`

* feat: Register admin OAuth strategy variants for all social providers

- Add admin strategy exports to Google, GitHub, Discord, Facebook, and
  Apple strategy files with admin callback URLs and existingUsersOnly
- Extract provider configs into reusable helpers to avoid duplication
  between regular and admin strategy constructors
- Re-export all admin strategy factories from strategies/index.js
- Register admin passport strategies (googleAdmin, githubAdmin, etc.)
  alongside regular ones in socialLogins.js when env vars are present

* feat: Add admin auth routes for SAML and social OAuth providers

- Add initiation and callback routes for SAML, Google, GitHub, Discord,
  Facebook, and Apple to the admin auth router
- Each provider follows the exchange code + PKCE pattern established by
  OpenID admin auth: store PKCE challenge on initiation, retrieve on
  callback, generate exchange code for the admin panel
- SAML and Apple use POST callbacks with state extracted from
  req.body.RelayState and req.body.state respectively
- Extract storePkceChallenge(), retrievePkceChallenge(), and
  generateState() helpers; refactor existing OpenID routes to use them
- All callback chains enforce requireAdminAccess, setBalanceConfig,
  checkDomainAllowed, and the shared createOAuthHandler
- No changes needed to the generic POST /oauth/exchange endpoint

* fix: Update SAML strategy test to handle dual strategy registration

setupSaml() now registers both 'saml' and 'samlAdmin' strategies,
causing the SamlStrategy mock to be called twice. The verifyCallback
variable was getting overwritten with the admin callback (which has
existingUsersOnly: true), making all new-user tests fail.

Fix: capture only the first callback per setupSaml() call and reset
between tests.

* fix: Address review findings for admin OAuth strategy changes

- Fix existingUsersOnly rejection in socialLogin.js to use
  cb(null, false, { message }) instead of cb(error), ensuring
  passport's failureRedirect fires correctly for admin flows
- Consolidate duplicate require() calls in strategies/index.js by
  destructuring admin exports from the already-imported default export
- Pass pre-parsed baseConfig to setupSamlAdmin() to avoid redundant
  certificate file I/O at startup
- Extract getGoogleConfig() helper in googleStrategy.js for consistency
  with all other provider strategy files
- Replace randomState() (openid-client) with generateState() (crypto)
  in the OpenID admin route for consistency with all other providers,
  and remove the now-unused openid-client import

* Reorder import statements in auth.js
2026-03-30 22:49:44 -04:00
..
appleStrategy.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
appleStrategy.test.js 🛂 feat: Social Login by Provider ID First then Email (#10358) 2025-11-05 09:20:35 -05:00
discordStrategy.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
facebookStrategy.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
githubStrategy.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
googleStrategy.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
index.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
jwtStrategy.js 🧑‍💻 refactor: Secure Field Selection for 2FA & API Build Sourcemap (#9087) 2025-08-15 18:55:49 -04:00
ldapStrategy.js 🏢 feat: Tenant-Scoped App Config in Auth Login Flows (#12434) 2026-03-27 16:08:43 -04:00
ldapStrategy.spec.js 🏢 feat: Tenant-Scoped App Config in Auth Login Flows (#12434) 2026-03-27 16:08:43 -04:00
localStrategy.js 📦 refactor: Consolidate DB models, encapsulating Mongoose usage in data-schemas (#11830) 2026-03-21 14:28:53 -04:00
openIdJwtStrategy.js 📌 fix: Populate userMessage.files Before First DB Save (#11939) 2026-02-26 09:16:45 -05:00
openIdJwtStrategy.spec.js 🛂 fix: Reject OpenID Email Fallback When Stored openidId Mismatches Token Sub (#12312) 2026-03-19 16:42:57 -04:00
openidStrategy.js 🏢 feat: Tenant-Scoped App Config in Auth Login Flows (#12434) 2026-03-27 16:08:43 -04:00
openidStrategy.spec.js 🏢 feat: Tenant-Scoped App Config in Auth Login Flows (#12434) 2026-03-27 16:08:43 -04:00
process.js 🛂 feat: Social Login by Provider ID First then Email (#10358) 2025-11-05 09:20:35 -05:00
process.test.js 🛂 feat: Social Login by Provider ID First then Email (#10358) 2025-11-05 09:20:35 -05:00
samlStrategy.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
samlStrategy.spec.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
socialLogin.js 🔐 feat: Admin Auth Support for SAML and Social OAuth Providers (#12472) 2026-03-30 22:49:44 -04:00
socialLogin.test.js 🏢 feat: Tenant-Scoped App Config in Auth Login Flows (#12434) 2026-03-27 16:08:43 -04:00
validators.js 🔐 feat: Add Configurable Min. Password Length (#9315) 2025-08-27 16:30:56 -04:00
validators.spec.js 🔐 feat: Add Configurable Min. Password Length (#9315) 2025-08-27 16:30:56 -04:00