LibreChat supports multiple authentication strategies to accommodate various organizational requirements. This guide covers setup for local email authentication, OAuth2 providers, LDAP, OpenID Connect, and SAML.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danny-avila/LibreChat/llms.txt
Use this file to discover all available pages before exploring further.
Authentication Strategies Overview
LibreChat implements authentication through Passport.js strategies located inapi/strategies/. The following authentication methods are available:
- Local Strategy (Email/Password)
- OAuth2 Providers (Google, GitHub, Discord, Facebook, Apple)
- LDAP (Lightweight Directory Access Protocol)
- OpenID Connect
- SAML (Security Assertion Markup Language)
Local Email/Password Authentication
Local authentication is enabled by default and uses email/password credentials stored in MongoDB.Configuration
Set JWT Secrets
Generate secure JWT secrets for session management:
.env
Generate secure secrets using:
openssl rand -hex 32Local Strategy Implementation
The local strategy (api/strategies/localStrategy.js) validates credentials and handles email verification:
api/strategies/localStrategy.js
OAuth2 Authentication
LibreChat supports multiple OAuth2 providers for social login.Enable Social Login
.env
Google OAuth2
Create Google OAuth Credentials
- Go to Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth 2.0 Client ID
- Configure the consent screen
- Add authorized redirect URI:
http://your-domain:3080/oauth/google/callback
GitHub OAuth2
Register GitHub OAuth App
- Go to GitHub Settings > Developer settings > OAuth Apps
- Click New OAuth App
- Set Authorization callback URL:
http://your-domain:3080/oauth/github/callback
Discord OAuth2
.env
Facebook OAuth2
.env
Apple OAuth2
.env
LDAP Authentication
LDAP authentication enables integration with Active Directory or other LDAP servers.Prerequisites
- Access to an LDAP server
- LDAP bind credentials (optional, for search operations)
- User search base DN
Configuration
Configure Bind Credentials
Set the bind DN and credentials for search operations:
.env
If your LDAP server allows anonymous bind, these can be omitted.
Set User Search Base
Define where to search for users:Common search filters:
.env
mail={{username}}- Search by emailuid={{username}}- Search by UIDsAMAccountName={{username}}- Search by Windows username
LDAP Strategy Implementation
The LDAP strategy (api/strategies/ldapStrategy.js) searches for users and creates/updates local records:
api/strategies/ldapStrategy.js
Active Directory Example
.env
OpenID Connect Authentication
OpenID Connect provides authentication through identity providers like Keycloak, Okta, or Azure AD.Configuration
.env
Role-Based Access Control
.env
Custom Claim Mapping
.env
Azure AD / Entra ID Example
.env
SAML Authentication
SAML authentication enables single sign-on with enterprise identity providers.Configuration
The SAML strategy (api/strategies/samlStrategy.js) requires configuration through environment variables or a dedicated SAML configuration file.
SAML configuration is complex and typically requires coordination with your identity provider administrator.
Domain Restrictions
Restrict user registration to specific email domains usinglibrechat.yaml:
librechat.yaml
Security Best Practices
- Always use HTTPS in production (
DOMAIN_SERVER=https://...) - Generate cryptographically secure JWT secrets
- Enable email verification (
ALLOW_UNVERIFIED_EMAIL_LOGIN=false) - Use strong password requirements (
MIN_PASSWORD_LENGTH=12or higher) - Implement rate limiting for authentication endpoints
- Regularly rotate JWT secrets and OAuth credentials
- Use secure LDAP connections (LDAPS or StartTLS)
- Restrict allowed email domains for registration
- Enable two-factor authentication when available
- Monitor authentication logs for suspicious activity
Troubleshooting
LDAP Connection Issues
OAuth2 Redirect URI Mismatch
EnsureDOMAIN_SERVER matches your OAuth2 provider’s registered redirect URI:
.env
https://chat.example.com/oauth/google/callback
Email Verification Not Working
Check email service configuration and ensureALLOW_UNVERIFIED_EMAIL_LOGIN is set appropriately:
Next Steps
- User Administration - Manage user accounts
- Permissions - Configure role-based access control
- Token Management - Manage user balances and credits