15 KiB
Authentik Setup Guide
This guide walks you through configuring Authentik for OAuth 2.0 / OpenID Connect authentication with the Feuerwehr Dashboard.
Table of Contents
- Prerequisites
- Authentik Installation
- Creating the Application
- Provider Configuration
- Redirect URIs Setup
- Scopes Configuration
- Getting Client Credentials
- Testing Authentication
- Common Issues
- Advanced Configuration
Prerequisites
Before you begin, you need:
- An Authentik instance (self-hosted or cloud)
- Admin access to Authentik
- Your Feuerwehr Dashboard URL (e.g.,
https://dashboard.yourdomain.com) - Your backend API URL (e.g.,
https://api.yourdomain.com)
Authentik Installation
If you don't have Authentik yet, here's a quick setup guide.
Option 1: Docker Compose (Recommended)
Create docker-compose.yml:
version: "3.8"
services:
postgresql:
image: postgres:16-alpine
restart: unless-stopped
volumes:
- database:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: ${PG_PASS:?database password required}
POSTGRES_USER: ${PG_USER:-authentik}
POSTGRES_DB: ${PG_DB:-authentik}
env_file:
- .env
redis:
image: redis:alpine
restart: unless-stopped
server:
image: ghcr.io/goauthentik/server:2024.2
restart: unless-stopped
command: server
environment:
AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
AUTHENTIK_POSTGRESQL__HOST: postgresql
AUTHENTIK_POSTGRESQL__NAME: ${PG_DB:-authentik}
AUTHENTIK_POSTGRESQL__USER: ${PG_USER:-authentik}
AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}
AUTHENTIK_REDIS__HOST: redis
ports:
- "${AUTHENTIK_PORT_HTTP:-9000}:9000"
- "${AUTHENTIK_PORT_HTTPS:-9443}:9443"
depends_on:
- postgresql
- redis
worker:
image: ghcr.io/goauthentik/server:2024.2
restart: unless-stopped
command: worker
environment:
AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
AUTHENTIK_POSTGRESQL__HOST: postgresql
AUTHENTIK_POSTGRESQL__NAME: ${PG_DB:-authentik}
AUTHENTIK_POSTGRESQL__USER: ${PG_USER:-authentik}
AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}
AUTHENTIK_REDIS__HOST: redis
depends_on:
- postgresql
- redis
volumes:
database:
driver: local
Create .env:
PG_PASS=<secure-database-password>
AUTHENTIK_SECRET_KEY=<generate-with-openssl-rand-base64-32>
AUTHENTIK_PORT_HTTP=9000
AUTHENTIK_PORT_HTTPS=9443
Start Authentik:
docker-compose up -d
Access Authentik at http://localhost:9000 and complete the initial setup wizard.
Option 2: Kubernetes
See Authentik Kubernetes Documentation for Helm charts.
Creating the Application
Step 1: Access Authentik Admin Interface
- Log in to your Authentik instance
- Navigate to Admin Interface (gear icon in top right)
Step 2: Create Provider
- In the admin panel, go to Applications → Providers
- Click Create button
- Select OAuth2/OpenID Provider
Configure the provider:
Name: Feuerwehr Dashboard Provider
Authorization Flow: default-provider-authorization-implicit-consent
Protocol Settings:
Client Type:
- Select:
Confidential
Client ID:
- Auto-generated (you'll copy this later)
- Or set custom:
feuerwehr-dashboard
Client Secret:
- Auto-generated (you'll copy this later)
Redirect URIs:
http://localhost:5173/auth/callback
http://localhost/auth/callback
https://dashboard.yourdomain.com/auth/callback
Add one URI per line. Include all environments (development, staging, production).
Signing Key:
- Select:
authentik Self-signed Certificate(default)
Token Validity:
Access token validity: 3600 (1 hour)
Refresh token validity: 86400 (24 hours)
Click Create to save the provider.
Step 3: Create Application
- Go to Applications → Applications
- Click Create button
Configure the application:
Name: Feuerwehr Dashboard
Slug: feuerwehr-dashboard
Provider: Feuerwehr Dashboard Provider (select from dropdown)
Launch URL: https://dashboard.yourdomain.com
UI Settings (optional):
Icon: (upload fire department logo)
Publisher: Your Fire Department Name
Description: Fire department operations dashboard
Click Create to save.
Step 4: Configure Scopes
- Go back to Providers → Feuerwehr Dashboard Provider
- Scroll to Advanced protocol settings
- Click Edit on Scopes
Ensure the following scopes are selected:
openid- Required for OpenID Connectprofile- User profile informationemail- User email address
Optional scopes:
offline_access- For refresh tokens (recommended)
Click Update.
Provider Configuration
Step 5: Configure Advanced Settings
Edit your provider and configure these advanced settings:
Token Settings:
Include claims in ID token: Yes
Access token validity: 3600 seconds (1 hour)
Refresh token validity: 86400 seconds (24 hours)
Subject Mode:
Based on the User's hashed ID
This ensures consistent user IDs.
Signing Algorithm:
RS256 (default)
Step 6: Configure Claims
Ensure the following claims are mapped:
Standard claims (should be automatic):
sub- Subject (user ID)email- User emailname- Full namepreferred_username- Usernamegiven_name- First namefamily_name- Last name
These are automatically included with the profile and email scopes.
Redirect URIs Setup
Your redirect URIs must match exactly between Authentik and your application.
Development Environment
http://localhost:5173/auth/callback
This is the Vite dev server URL.
Production Environment
https://dashboard.yourdomain.com/auth/callback
Replace yourdomain.com with your actual domain.
Docker Local Testing
http://localhost/auth/callback
http://localhost:80/auth/callback
For testing the production Docker build locally.
Important Notes
- URLs are case-sensitive
- Must include protocol (
http://orhttps://) - No trailing slashes
- Port numbers must match if specified
Scopes Configuration
Required Scopes
Your application requires these scopes:
- openid - Identifies this as an OpenID Connect request
- profile - Provides basic profile information
- email - Provides user email address
Requesting Scopes
The dashboard automatically requests these scopes in the OAuth flow.
Backend configuration (backend/src/config/oauth.ts):
scopes: ['openid', 'profile', 'email']
Frontend login flow (frontend/src/services/authService.ts):
const scopes = 'openid profile email';
Getting Client Credentials
Step 7: Copy Client Credentials
- Go to Applications → Providers
- Click on Feuerwehr Dashboard Provider
- Find the Client ID and Client Secret
Client ID: Will look like abc123def456... or custom feuerwehr-dashboard
Client Secret: Click the eye icon to reveal, then copy button
Step 8: Get Provider URLs
-
In the provider details, find OpenID Configuration URL:
https://auth.yourdomain.com/application/o/feuerwehr-dashboard/.well-known/openid-configuration -
Important URLs from this configuration:
- Issuer:
https://auth.yourdomain.com/application/o/feuerwehr-dashboard/ - Authorization Endpoint: Auto-discovered
- Token Endpoint: Auto-discovered
- Userinfo Endpoint: Auto-discovered
- Issuer:
Step 9: Configure Dashboard
Update your Feuerwehr Dashboard .env file:
# Authentik OAuth Configuration
AUTHENTIK_CLIENT_ID=<your-client-id>
AUTHENTIK_CLIENT_SECRET=<your-client-secret>
AUTHENTIK_ISSUER=https://auth.yourdomain.com/application/o/feuerwehr-dashboard/
AUTHENTIK_REDIRECT_URI=https://dashboard.yourdomain.com/auth/callback
# For development, use:
# AUTHENTIK_ISSUER=http://localhost:9000/application/o/feuerwehr-dashboard/
# AUTHENTIK_REDIRECT_URI=http://localhost:5173/auth/callback
Important: The AUTHENTIK_ISSUER must end with a trailing slash /.
Testing Authentication
Step 10: Test the Flow
-
Start your application:
# Development cd backend && npm run dev cd frontend && npm run dev # Or production make prod -
Open the dashboard in your browser:
Development: http://localhost:5173 Production: https://dashboard.yourdomain.com -
Click "Login" button
-
You should be redirected to Authentik login page
-
Enter your Authentik credentials
-
Consent screen (if enabled):
- Review permissions
- Click "Authorize"
-
Redirect back to dashboard:
- Should show your dashboard
- User profile should be loaded
- Check browser console for any errors
Step 11: Verify Token Exchange
Check backend logs:
make logs-prod
# or
cd backend && npm run dev
Look for:
[INFO] OAuth callback received
[INFO] Token exchange successful
[INFO] User authenticated: <username>
Step 12: Test User Profile
In the dashboard:
- Navigate to Profile page
- Verify your information is displayed:
- Username
- Name
Step 13: Test Logout
- Click "Logout" button
- Should redirect to login page
- Verify session is cleared
- Attempting to access dashboard should redirect to login
Common Issues
Issue 1: Redirect URI Mismatch
Error: redirect_uri_mismatch or invalid_redirect_uri
Solution:
- Check the redirect URI in Authentik exactly matches your app
- Include protocol (
http://orhttps://) - Check for trailing slashes
- Verify port numbers match
Issue 2: Invalid Client Credentials
Error: invalid_client
Solution:
- Verify
AUTHENTIK_CLIENT_IDis correct - Verify
AUTHENTIK_CLIENT_SECRETis correct (no extra spaces) - Check if client secret was regenerated in Authentik
- Ensure client type is "Confidential"
Issue 3: CORS Errors
Error: CORS policy blocked request
Solution:
- Ensure
CORS_ORIGINin backend.envmatches frontend URL - For development:
CORS_ORIGIN=http://localhost:5173 - For production:
CORS_ORIGIN=https://dashboard.yourdomain.com - Restart backend after changing CORS settings
Issue 4: Token Validation Failed
Error: Invalid token or Token signature verification failed
Solution:
- Verify
AUTHENTIK_ISSUERURL is correct - Ensure issuer URL ends with
/ - Check Authentik is accessible from backend server
- Verify JWT signing key hasn't changed
Issue 5: Scope Errors
Error: invalid_scope or missing user data
Solution:
- Ensure
openid,profile,emailscopes are configured in Authentik - Check scopes are requested in login flow
- Verify user has consented to scopes
Issue 6: User Not Created in Database
Error: Authentication works but user not found
Solution:
- Check backend logs for database errors
- Verify database migrations ran
- Check
userstable exists:docker exec -it feuerwehr_db_prod psql -U prod_user -d feuerwehr_prod -c "\dt" - Manually run migrations if needed
Issue 7: Token Refresh Fails
Error: Refresh token invalid or expired
Solution:
- Check token validity settings in Authentik
- Increase refresh token validity (e.g., 86400 seconds)
- Verify
offline_accessscope is included - Clear browser cookies and re-authenticate
Advanced Configuration
Customizing Login Flow
Create custom authentication flow in Authentik:
- Go to Flows & Stages → Flows
- Duplicate
default-provider-authorization-implicit-consent - Add custom stages (MFA, email verification, etc.)
- Update provider to use custom flow
Adding Multi-Factor Authentication
- Go to Flows & Stages → Stages
- Create authenticator validation stage
- Add to your authorization flow
- Users will be prompted for MFA on login
Branding
Customize Authentik appearance:
- Go to System → Branding
- Upload logo
- Set primary color to match fire department branding
- Configure footer links
User Management
Add users to Authentik:
- Go to Directory → Users
- Click Create
- Fill in user details
- Set password
- Assign to groups (if using RBAC)
Group-Based Access Control
Implement role-based access:
- Create groups in Directory → Groups
- Assign users to groups
- In your app, read
groupsclaim from token - Implement authorization based on groups
Example groups:
feuerwehr-admin- Full accessfeuerwehr-operator- Standard accessfeuerwehr-viewer- Read-only access
Testing Checklist
After configuration, verify:
- Login redirects to Authentik
- Successful authentication redirects back
- User profile loads correctly
- Tokens are stored securely
- Logout clears session
- Token refresh works
- Protected routes require authentication
- Invalid tokens are rejected
- CORS is properly configured
- Works on all browsers (Chrome, Firefox, Safari)
Configuration Reference
Minimum Required Settings
Authentik Provider:
Client Type: Confidential
Client ID: <auto-generated>
Client Secret: <auto-generated>
Redirect URIs: https://dashboard.yourdomain.com/auth/callback
Scopes: openid, profile, email
Access Token Validity: 3600
Refresh Token Validity: 86400
Dashboard .env:
AUTHENTIK_CLIENT_ID=<from-authentik>
AUTHENTIK_CLIENT_SECRET=<from-authentik>
AUTHENTIK_ISSUER=https://auth.yourdomain.com/application/o/feuerwehr-dashboard/
AUTHENTIK_REDIRECT_URI=https://dashboard.yourdomain.com/auth/callback
Security Best Practices
- Use HTTPS in production - Never use HTTP for OAuth flows
- Keep secrets secret - Never commit credentials to Git
- Rotate secrets regularly - Change client secrets periodically
- Use strong passwords - For Authentik admin and users
- Enable MFA - Require multi-factor authentication for admin users
- Monitor logs - Watch for failed login attempts
- Limit token validity - Use short-lived access tokens
- Validate redirect URIs - Only allow known URLs
Additional Resources
Support
If you encounter issues:
- Check Authentik logs:
docker-compose logs -f server - Check dashboard backend logs:
make logs-prod - Review browser console for errors
- Consult Common Issues section
- Search Authentik GitHub issues
- Create detailed issue report
Next Steps: After completing Authentik setup, proceed to DEPLOYMENT.md for production deployment.