OAuth & LDAP Integration
Integrate with OAuth2/OIDC providers and LDAP/Active Directory.
Overview
EZ-Console supports external authentication through OAuth2/OIDC providers (Google, Azure AD, Okta, etc.) and LDAP/Active Directory. This allows users to sign in with their existing corporate credentials.
OAuth2/OIDC Integration
Configuration
OAuth providers are configured in config.yml:
oauth:
enabled: true
providers:
- name: "google"
display_name: "Google"
client_id: "your-client-id"
client_secret: "your-client-secret"
icon_url: "https://example.com/google-icon.png"
auth_url: "https://accounts.google.com/o/oauth2/v2/auth"
token_url: "https://oauth2.googleapis.com/token"
user_info_url: "https://www.googleapis.com/oauth2/v2/userinfo"
redirect_url: "http://localhost:5173/login?provider=google"
role_field: "role" # Optional: field in user info for role
email_field: "email" # Optional: default "email"
username_field: "username" # Optional: default "username"
full_name_field: "fullName" # Optional: default "fullName"
avatar_field: "avatar" # Optional: default "avatar"
auto_create_user: true # Optional: auto create user on first login
Google OAuth Setup
-
Create OAuth Client:
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:5173/login?provider=google
-
Configuration:
oauth:
enabled: true
providers:
- name: "google"
display_name: "Google"
client_id: "YOUR_GOOGLE_CLIENT_ID"
client_secret: "YOUR_GOOGLE_CLIENT_SECRET"
auth_url: "https://accounts.google.com/o/oauth2/v2/auth"
token_url: "https://oauth2.googleapis.com/token"
user_info_url: "https://www.googleapis.com/oauth2/v2/userinfo"
redirect_url: "http://localhost:5173/login?provider=google"
Azure AD Setup
-
Register Application:
- Go to Azure Portal
- Azure Active Directory → App registrations
- New registration
- Add redirect URI:
http://localhost:5173/login?provider=azure_ad
-
Configuration:
oauth:
enabled: true
providers:
- name: "azure_ad"
display_name: "Azure AD"
client_id: "YOUR_AZURE_CLIENT_ID"
client_secret: "YOUR_AZURE_CLIENT_SECRET"
auth_url: "https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize"
token_url: "https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token"
user_info_url: "https://graph.microsoft.com/v1.0/me"
redirect_url: "http://localhost:5173/login?provider=azure_ad"
Okta Setup
-
Create Application:
- Go to Okta Admin Console
- Applications → Create App Integration
- OIDC - OpenID Connect
- Add redirect URI:
http://localhost:5173/login?provider=okta
-
Configuration:
oauth:
enabled: true
providers:
- name: "okta"
display_name: "Okta"
client_id: "YOUR_OKTA_CLIENT_ID"
client_secret: "YOUR_OKTA_CLIENT_SECRET"
auth_url: "https://{your-domain}.okta.com/oauth2/v1/authorize"
token_url: "https://{your-domain}.okta.com/oauth2/v1/token"
user_info_url: "https://{your-domain}.okta.com/oauth2/v1/userinfo"
redirect_url: "http://localhost:5173/login?provider=okta"
Custom OAuth Provider
oauth:
enabled: true
providers:
- name: "custom"
display_name: "Custom Provider"
client_id: "your-client-id"
client_secret: "your-client-secret"
auth_url: "https://provider.com/oauth/authorize"
token_url: "https://provider.com/oauth/token"
user_info_url: "https://provider.com/api/user"
redirect_url: "http://localhost:5173/login?provider=custom"
LDAP/Active Directory Integration
Configuration
LDAP settings are configured through the admin console or API:
Navigate to: System Settings → LDAP Settings
Basic LDAP Configuration
ldap:
enabled: true
host: "ldap.example.com"
port: 389
use_tls: false
use_ssl: false
base_dn: "dc=example,dc=com"
bind_dn: "cn=admin,dc=example,dc=com"
bind_password: "password"
user_search_base: "ou=users,dc=example,dc=com"
user_search_filter: "(uid=%s)"
group_search_base: "ou=groups,dc=example,dc=com"
group_search_filter: "(member=%s)"
Active Directory Configuration
ldap:
enabled: true
host: "ad.example.com"
port: 389
use_tls: true
base_dn: "dc=example,dc=com"
bind_dn: "CN=Service Account,CN=Users,DC=example,DC=com"
bind_password: "password"
user_search_base: "CN=Users,DC=example,DC=com"
user_search_filter: "(&(objectClass=user)(sAMAccountName=%s))"
group_search_base: "CN=Users,DC=example,DC=com"
group_search_filter: "(&(objectClass=group)(member=%s))"
Configuration Options
- enabled: Enable LDAP authentication (default:
false) - host: LDAP server hostname (required)
- port: LDAP server port (default:
389for LDAP,636for LDAPS) - use_tls: Use TLS encryption (default:
false) - use_ssl: Use SSL encryption (default:
false) - base_dn: Base distinguished name (required)
- bind_dn: Bind distinguished name for authentication (required)
- bind_password: Bind password (required)
- user_search_base: Base DN for user search (required)
- user_search_filter: LDAP filter for user search (default:
"(uid=%s)") - group_search_base: Base DN for group search (optional)
- group_search_filter: LDAP filter for group search (optional)
Testing Connections
Test OAuth Connection
- Navigate to System Settings → OAuth Settings
- Click Test Connection for a provider
- Verify redirect works correctly
Test LDAP Connection
- Navigate to System Settings → LDAP Settings
- Enter LDAP configuration
- Click Test Connection
- Enter test username and password
- Verify connection and authentication
User Mapping
OAuth User Mapping
OAuth providers return user information that is mapped to EZ-Console users:
- email: User email address
- username: Username (from
username_fieldor email) - full_name: Full name
- avatar: Avatar URL
- role: Role assignment (if
role_fieldis configured)
LDAP User Mapping
LDAP attributes are mapped to user fields:
- username: From
user_search_filterresult - email: From
mailattribute - full_name: From
cnordisplayNameattribute - groups: From group search results
Auto User Creation
OAuth Auto Creation
When auto_create_user: true:
- Users are automatically created on first OAuth login
- Default role can be assigned
- User information is synced from OAuth provider
LDAP Auto Creation
- Users can be automatically created on first LDAP login
- User information is synced from LDAP
- Groups can be mapped to roles
Troubleshooting
OAuth Issues
Redirect URI Mismatch:
- Verify redirect URI matches exactly in provider settings
- Check for trailing slashes
- Ensure protocol (http/https) matches
Invalid Client Credentials:
- Verify client ID and secret are correct
- Check if credentials are expired
- Verify application is enabled in provider
LDAP Issues
Connection Failed:
- Verify host and port are correct
- Check firewall rules
- Verify TLS/SSL settings match server
Authentication Failed:
- Verify bind DN and password
- Check user search filter
- Verify user exists in LDAP
User Not Found:
- Check user search base and filter
- Verify user DN format
- Check LDAP permissions
Best Practices
1. Use HTTPS in Production
Always use HTTPS for OAuth redirects and LDAP connections in production.
2. Secure Credentials
Store OAuth client secrets and LDAP passwords securely, never in code.
3. Test Before Production
Always test OAuth and LDAP connections in staging before production.
4. Monitor Logs
Monitor authentication logs for failed attempts and connection issues.
Related Topics
- Authentication & Authorization - Auth implementation
- System Settings - System configuration
Need help? Ask in GitHub Discussions.