Merge origin/main into feature branch, resolving 3 conflicts: - app/api/__init__.py: add classification_rules_router alongside new routers from main (audit_logs, i18n, mobile, compliance, translation) - app/models.py: keep ClassificationRuleModel alongside new models from main (MobileDevice, ComplianceTemplate, PipelineRoutingRule) - tests/conftest.py: import both ClassificationRuleModel and new models from main (AuditLog, ComplianceTemplate) Also renumber migration from 027 to 037 to chain from the latest migration on main (036_add_document_translation_fields). Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
8.2 KiB
Setting up Authentication
This guide explains how to configure authentication for DocuElevate to secure your installation.
Required Configuration Parameters
| Variable | Description |
|---|---|
AUTH_ENABLED |
Enable or disable authentication (True/False) |
SESSION_SECRET |
Secret key for session encryption (min 32 characters) |
ADMIN_USERNAME |
Username for basic authentication |
ADMIN_PASSWORD |
Password for basic authentication |
ADMIN_GROUP_NAME |
OIDC group name that grants admin access (default: admin) |
AUTHENTIK_CLIENT_ID |
Client ID for OpenID Connect authentication |
AUTHENTIK_CLIENT_SECRET |
Client secret for OpenID Connect authentication |
AUTHENTIK_CONFIG_URL |
OpenID Connect discovery URL |
OAUTH_PROVIDER_NAME |
Display name for the OAuth provider button |
For a complete list of configuration options, see the Configuration Guide.
Authentication Methods
DocuElevate supports multiple authentication methods that can be used independently or together:
- Simple Authentication - Basic username/password authentication managed by DocuElevate
- OpenID Connect - Integration with identity providers like Authentik, Keycloak, or Auth0
- Social Login - Sign in with Google, Microsoft, Apple, or Dropbox accounts (see Social Login Setup Guide)
Session Security
DocuElevate uses FastAPI's session management to maintain user sessions. The session data is stored in cookies that are encrypted and signed using your application's secret key. This prevents tampering with session data while ensuring users remain authenticated between requests.
The SESSION_SECRET is automatically used by the web framework to:
- Encrypt and sign session cookies
- Protect against cross-site request forgery (CSRF) attacks
- Secure other session-related functionality
Always use a strong, randomly generated secret key of at least 32 characters for production environments.
Generating a Secure Session Secret
You can generate a secure random string using Python:
import secrets
print(secrets.token_hex(32)) # Outputs a 64-character hex string (32 bytes)
Or using OpenSSL:
openssl rand -hex 32
Make sure to keep this secret value confidential and don't reuse it across different applications.
Setting up Simple Authentication
For smaller deployments or testing, simple authentication is easy to set up:
-
In your
.envfile, set:AUTH_ENABLED=True SESSION_SECRET=your-secure-random-string-at-least-32-chars ADMIN_USERNAME=your_admin_username ADMIN_PASSWORD=your_secure_password ADMIN_GROUP_NAME=admin -
Restart DocuElevate to apply the changes
-
When you navigate to the application, you'll be prompted to log in with the credentials you set
Setting up OpenID Connect with Authentik
For larger deployments or when you need more advanced authentication features, OpenID Connect (OIDC) is recommended:
1. Create an Application in Authentik
-
Log in to your Authentik admin interface
-
Navigate to "Applications" > "Applications"
-
Click "Create"
-
Fill in the following details:
- Name: DocuElevate
- Slug: docuelevate
- Provider: Create a new OAuth2/OIDC Provider
- Launch URL: The URL of your DocuElevate instance (e.g., https://docuelevate.example.com)
-
For the OAuth2/OIDC Provider settings:
- Client Type: Confidential
- Redirect URIs: https://docuelevate.example.com/auth (adjust for your domain)
- Signing Key: Select an appropriate signing key
- Scopes: Select "openid", "email", and "profile" at minimum
-
Save the provider and then the application
-
Note down the Client ID and Client Secret from the provider details
2. Configure DocuElevate
-
In your
.envfile, set:AUTH_ENABLED=True SESSION_SECRET=your-secure-random-string-at-least-32-chars AUTHENTIK_CLIENT_ID=your_client_id_from_authentik AUTHENTIK_CLIENT_SECRET=your_client_secret_from_authentik AUTHENTIK_CONFIG_URL=https://auth.example.com/application/o/docuelevate/.well-known/openid-configuration OAUTH_PROVIDER_NAME=Authentik SSO -
Adjust the
AUTHENTIK_CONFIG_URLto match your Authentik instance and application slug -
Restart DocuElevate to apply the changes
3. Test the Authentication
- Navigate to your DocuElevate instance
- You should be redirected to the Authentik login page
- After successful authentication, you'll be redirected back to DocuElevate
Using Other OpenID Connect Providers
DocuElevate can work with any OpenID Connect-compliant provider, not just Authentik:
Keycloak Setup
-
Create a client in Keycloak with:
- Client ID: your preferred client ID
- Access Type: confidential
- Valid Redirect URIs: https://docuelevate.example.com/auth
-
Get the client secret from the "Credentials" tab
-
Configure DocuElevate with:
AUTHENTIK_CLIENT_ID=your_keycloak_client_id AUTHENTIK_CLIENT_SECRET=your_keycloak_client_secret AUTHENTIK_CONFIG_URL=https://keycloak.example.com/auth/realms/your-realm/.well-known/openid-configuration OAUTH_PROVIDER_NAME=Keycloak SSO
Auth0 Setup
- Create a new application in Auth0
- Get your client ID and secret
- Set the callback URL to https://docuelevate.example.com/auth
- Configure DocuElevate with:
AUTHENTIK_CLIENT_ID=your_auth0_client_id AUTHENTIK_CLIENT_SECRET=your_auth0_client_secret AUTHENTIK_CONFIG_URL=https://your-tenant.auth0.com/.well-known/openid-configuration OAUTH_PROVIDER_NAME=Auth0
Security Considerations
- Always use HTTPS in production to protect authentication tokens and passwords
- Generate a strong, random
SESSION_SECRET(at least 32 characters) - Use strong passwords for simple authentication
- Consider using a password manager to generate and store your admin credentials
- Restrict the scopes requested from your OIDC provider to only what's needed
- Consider setting up user groups and permissions in your identity provider
- If using simple authentication in production, consider implementing rate limiting for login attempts
Troubleshooting Authentication Issues
If you encounter issues with authentication:
-
Login failures with simple authentication:
- Verify that the username and password exactly match the values in your
.envfile - Check if there are leading or trailing spaces in your credentials
- Ensure your
.envfile is properly loaded by the application
- Verify that the username and password exactly match the values in your
-
Session issues:
- Check that your
SESSION_SECRETis set correctly - Clear browser cookies and cache if experiencing persistent login issues
- Check that your
-
OIDC issues:
- Redirect URI mismatch: Ensure the redirect URI in your provider configuration exactly matches your DocuElevate URL + "/auth"
- SSL-related errors: Make sure your certificates are valid and trusted
- Provider connectivity: Ensure DocuElevate can reach your identity provider
-
Token validation errors:
- Check that the clocks are synchronized between DocuElevate and the identity provider
- Verify that the signing keys are correctly configured
-
Debug OpenID information:
- For most providers, you can visit the
/.well-known/openid-configurationendpoint to verify their settings
- For most providers, you can visit the
For more general configuration issues, see the Configuration Troubleshooting Guide.
Social Login
DocuElevate supports social login with Google, Microsoft, Apple, and Dropbox. Social login allows users to authenticate using their existing accounts with these providers, without needing a separate DocuElevate password.
Social login can be used alongside any other authentication method (simple auth, OIDC, local signup). Each social provider is independently configured.
For detailed setup instructions, prerequisites, and provider-specific configuration, see the Social Login Setup Guide.