13 KiB
OIDC Authentication Setup Guide
This guide explains how to configure OpenID Connect (OIDC) authentication for Readur, allowing users to sign in using external identity providers like Google, Microsoft Azure AD, Keycloak, Auth0, or any OIDC-compliant provider.
Table of Contents
- Overview
- Prerequisites
- Configuration
- Identity Provider Setup
- Testing the Setup
- User Experience
- Troubleshooting
- Security Considerations
Overview
OIDC authentication in Readur provides:
- Single Sign-On (SSO): Users can sign in with existing corporate accounts
- Centralized User Management: User provisioning handled by your identity provider
- Enhanced Security: No need to manage passwords in Readur
- Seamless Integration: Works alongside existing local authentication
When OIDC is enabled, users will see a "Sign in with OIDC" button on the login page alongside the standard username/password form.
Prerequisites
Before configuring OIDC, ensure you have:
- Access to an OIDC Provider: Google, Microsoft, Keycloak, Auth0, etc.
- Ability to Register Applications: Admin access to create OAuth2/OIDC applications
- Network Connectivity: Readur server can reach the OIDC provider endpoints
- SSL/TLS Setup: HTTPS is strongly recommended for production deployments
Configuration
Environment Variables
Configure OIDC by setting these environment variables:
| Variable | Required | Description | Example |
|---|---|---|---|
OIDC_ENABLED |
✅ | Enable OIDC authentication | true |
OIDC_CLIENT_ID |
✅ | OAuth2 client ID from your provider | readur-app-client-id |
OIDC_CLIENT_SECRET |
✅ | OAuth2 client secret from your provider | very-secret-key |
OIDC_ISSUER_URL |
✅ | OIDC provider's issuer URL | https://accounts.google.com |
OIDC_REDIRECT_URI |
✅ | Callback URL for your Readur instance | https://readur.company.com/auth/oidc/callback |
Example Configurations
Basic OIDC Setup
# Enable OIDC
OIDC_ENABLED=true
# Provider settings (example for Google)
OIDC_CLIENT_ID=123456789-abcdefgh.apps.googleusercontent.com
OIDC_CLIENT_SECRET=GOCSPX-your-secret-key
OIDC_ISSUER_URL=https://accounts.google.com
OIDC_REDIRECT_URI=https://readur.company.com/auth/oidc/callback
Development Setup
# Enable OIDC for development
OIDC_ENABLED=true
# Local development settings
OIDC_CLIENT_ID=dev-client-id
OIDC_CLIENT_SECRET=dev-client-secret
OIDC_ISSUER_URL=https://your-keycloak.company.com/auth/realms/readur
OIDC_REDIRECT_URI=http://localhost:8000/auth/oidc/callback
Docker Compose Setup
version: '3.8'
services:
readur:
image: readur:latest
environment:
# Core settings
DATABASE_URL: postgresql://readur:readur@postgres:5432/readur
# OIDC configuration
OIDC_ENABLED: "true"
OIDC_CLIENT_ID: "${OIDC_CLIENT_ID}"
OIDC_CLIENT_SECRET: "${OIDC_CLIENT_SECRET}"
OIDC_ISSUER_URL: "${OIDC_ISSUER_URL}"
OIDC_REDIRECT_URI: "https://readur.company.com/auth/oidc/callback"
ports:
- "8000:8000"
Identity Provider Setup
Google OAuth 2.0
-
Create a Project in Google Cloud Console
-
Enable Google+ API:
- Go to "APIs & Services" → "Library"
- Search for "Google+ API" and enable it
-
Create OAuth 2.0 Credentials:
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "OAuth 2.0 Client ID"
- Application type: "Web application"
- Name: "Readur Document Management"
-
Configure Redirect URIs:
Authorized redirect URIs: https://your-readur-domain.com/auth/oidc/callback http://localhost:8000/auth/oidc/callback (for development) -
Environment Variables:
OIDC_ENABLED=true OIDC_CLIENT_ID=123456789-abcdefgh.apps.googleusercontent.com OIDC_CLIENT_SECRET=GOCSPX-your-secret-key OIDC_ISSUER_URL=https://accounts.google.com OIDC_REDIRECT_URI=https://your-readur-domain.com/auth/oidc/callback
Microsoft Azure AD
-
Register an Application in Azure Portal:
- Go to "Azure Active Directory" → "App registrations"
- Click "New registration"
- Name: "Readur Document Management"
- Supported account types: Choose based on your needs
- Redirect URI:
https://your-readur-domain.com/auth/oidc/callback
-
Configure Authentication:
- In your app registration, go to "Authentication"
- Add platform: "Web"
- Add redirect URIs as needed
- Enable "ID tokens" under "Implicit grant and hybrid flows"
-
Create Client Secret:
- Go to "Certificates & secrets"
- Click "New client secret"
- Add description and choose expiration
- Copy the secret value immediately (you won't see it again)
-
Get Tenant Information:
- Note your Tenant ID from the "Overview" page
- Issuer URL format:
https://login.microsoftonline.com/{tenant-id}/v2.0
-
Environment Variables:
OIDC_ENABLED=true OIDC_CLIENT_ID=12345678-1234-1234-1234-123456789012 OIDC_CLIENT_SECRET=your-client-secret OIDC_ISSUER_URL=https://login.microsoftonline.com/your-tenant-id/v2.0 OIDC_REDIRECT_URI=https://your-readur-domain.com/auth/oidc/callback
Keycloak
-
Create a Realm (or use existing):
- Access Keycloak admin console
- Create or select a realm for Readur
-
Create a Client:
- Go to "Clients" → "Create"
- Client ID:
readur - Client Protocol:
openid-connect - Root URL:
https://your-readur-domain.com
-
Configure Client Settings:
- Access Type:
confidential - Standard Flow Enabled:
ON - Valid Redirect URIs:
https://your-readur-domain.com/auth/oidc/callback* - Web Origins:
https://your-readur-domain.com
- Access Type:
-
Get Client Secret:
- Go to "Credentials" tab
- Copy the client secret
-
Environment Variables:
OIDC_ENABLED=true OIDC_CLIENT_ID=readur OIDC_CLIENT_SECRET=your-keycloak-client-secret OIDC_ISSUER_URL=https://keycloak.company.com/auth/realms/your-realm OIDC_REDIRECT_URI=https://your-readur-domain.com/auth/oidc/callback
Auth0
-
Create an Application in Auth0 Dashboard:
- Go to "Applications" → "Create Application"
- Name: "Readur Document Management"
- Application Type: "Regular Web Applications"
-
Configure Settings:
- Allowed Callback URLs:
https://your-readur-domain.com/auth/oidc/callback - Allowed Web Origins:
https://your-readur-domain.com - Allowed Logout URLs:
https://your-readur-domain.com/login
- Allowed Callback URLs:
-
Get Credentials:
- Note the Client ID and Client Secret from the "Settings" tab
- Domain will be something like
your-app.auth0.com
-
Environment Variables:
OIDC_ENABLED=true OIDC_CLIENT_ID=your-auth0-client-id OIDC_CLIENT_SECRET=your-auth0-client-secret OIDC_ISSUER_URL=https://your-app.auth0.com OIDC_REDIRECT_URI=https://your-readur-domain.com/auth/oidc/callback
Generic OIDC Provider
For any OIDC-compliant provider:
- Register Your Application with the provider
- Configure Redirect URI:
https://your-readur-domain.com/auth/oidc/callback - Get Credentials: Client ID, Client Secret, and Issuer URL
- Set Environment Variables:
OIDC_ENABLED=true OIDC_CLIENT_ID=your-client-id OIDC_CLIENT_SECRET=your-client-secret OIDC_ISSUER_URL=https://your-provider.com OIDC_REDIRECT_URI=https://your-readur-domain.com/auth/oidc/callback
Testing the Setup
1. Verify Configuration Loading
When starting Readur, check the logs for OIDC configuration:
✅ OIDC_ENABLED: true (loaded from env)
✅ OIDC_CLIENT_ID: your-client-id (loaded from env)
✅ OIDC_CLIENT_SECRET: ***hidden*** (loaded from env, 32 chars)
✅ OIDC_ISSUER_URL: https://accounts.google.com (loaded from env)
✅ OIDC_REDIRECT_URI: https://your-domain.com/auth/oidc/callback (loaded from env)
2. Test Discovery Endpoint
Verify your provider's discovery endpoint works:
curl https://accounts.google.com/.well-known/openid-configuration
Should return JSON with authorization_endpoint, token_endpoint, and userinfo_endpoint.
3. Test Login Flow
- Navigate to your Readur login page
- Click "Sign in with OIDC"
- You should be redirected to your identity provider
- After authentication, you should be redirected back to Readur dashboard
4. Check User Creation
Verify that OIDC users are created correctly:
- Check database for new users with
auth_provider = 'oidc' - Ensure
oidc_subject,oidc_issuer, andoidc_emailfields are populated - Verify users can access the dashboard
User Experience
First-Time Login
When a user signs in with OIDC for the first time:
- User clicks "Sign in with OIDC"
- Redirected to identity provider for authentication
- After successful authentication, a new Readur account is created
- User information is populated from OIDC claims:
- Username: Derived from
preferred_usernameoremail - Email: From
emailclaim - OIDC Subject: Unique identifier from
subclaim - Auth Provider: Set to
oidc
- Username: Derived from
Subsequent Logins
For returning users:
- User clicks "Sign in with OIDC"
- Readur matches the user by
oidc_subjectandoidc_issuer - User is automatically signed in without creating a duplicate account
Mixed Authentication
- Local users can continue using username/password
- OIDC users are created as separate accounts
- Administrators can manage both types of users
- No automatic account linking between local and OIDC accounts
Troubleshooting
Common Issues
"OIDC client ID not configured"
Problem: OIDC environment variables not set correctly
Solution:
# Verify environment variables are set
echo $OIDC_ENABLED
echo $OIDC_CLIENT_ID
echo $OIDC_ISSUER_URL
# Check for typos in variable names
env | grep OIDC
"Failed to discover OIDC endpoints"
Problem: Cannot reach the OIDC discovery endpoint
Solutions:
- Verify
OIDC_ISSUER_URLis correct - Test connectivity:
curl https://your-issuer/.well-known/openid-configuration - Check firewall and network settings
- Ensure DNS resolution works
"Invalid redirect_uri"
Problem: Redirect URI mismatch between Readur and identity provider
Solutions:
- Verify
OIDC_REDIRECT_URImatches exactly in both places - Check for trailing slashes, HTTP vs HTTPS
- Ensure the provider allows your redirect URI
"Authentication failed: access_denied"
Problem: User denied access or provider restrictions
Solutions:
- Check user permissions in identity provider
- Verify the application is enabled for the user
- Review provider-specific restrictions
"Invalid authorization code"
Problem: Issues with the OAuth2 flow
Solutions:
- Check system clock synchronization
- Verify client secret is correct
- Look for network issues during token exchange
Debug Mode
Enable detailed logging for OIDC troubleshooting:
RUST_LOG=debug
This will show detailed information about:
- OIDC discovery process
- Token exchange
- User information retrieval
- Error details
Testing with curl
Test the callback endpoint manually:
# Test the OIDC callback endpoint (after getting an auth code)
curl -X GET "https://your-readur-domain.com/api/auth/oidc/callback?code=AUTH_CODE&state=STATE"
Security Considerations
Production Deployment
-
Use HTTPS: Always use HTTPS in production
OIDC_REDIRECT_URI=https://readur.company.com/auth/oidc/callback -
Secure Client Secret: Store client secrets securely
- Use environment variables or secret management systems
- Never commit secrets to version control
- Rotate secrets regularly
-
Validate Redirect URIs: Ensure your identity provider only allows valid redirect URIs
-
Network Security: Restrict network access between Readur and identity provider
User Management
- Account Mapping: OIDC users are identified by
oidc_subject+oidc_issuer - No Password: OIDC users don't have passwords in Readur
- User Deletion: Deleting users from identity provider doesn't automatically remove them from Readur
- Role Management: Configure user roles in Readur or map from OIDC claims
Monitoring
Monitor OIDC authentication:
- Failed authentication attempts
- Token validation errors
- User creation patterns
- Provider availability
Next Steps
After setting up OIDC:
- Test Thoroughly: Test with different user accounts and scenarios
- User Training: Inform users about the new login option
- Monitor Usage: Track authentication patterns and issues
- Backup Strategy: Ensure you can recover access if OIDC provider is unavailable
- Documentation: Document your specific provider configuration for your team
For additional help:
- Review the configuration guide for general settings
- Check the deployment guide for production setup
- See the user guide for end-user documentation