How to Configure Authentik OIDC¶
Configure OIDC authentication using Authentik and Terraform automation.
Automated Setup (Recommended)¶
Terraform creates:
- OIDC provider
- OAuth2 application
- Test users (alice, bob, charlie)
- Updates .env with client secret
Manual Setup¶
1. Access Authentik Admin¶
Open http://authentik-server:9000 and login as akadmin.
2. Create OIDC Provider¶
- Admin > Providers > Create
- Select OAuth2/OpenID Provider
- Configure:
- Name: webapp-provider
- Authorization flow: default-provider-authorization-implicit-consent
- Client type: Confidential
- Client ID: webapp
- Redirect URIs: http://localhost:8000/auth/callback
3. Create Application¶
- Admin > Applications > Create
- Configure:
- Name: FastAPI Topaz Webapp
- Slug: webapp
- Provider: webapp-provider
- Launch URL: http://localhost:8000
4. Create Test Users¶
- Directory > Users > Create
- For each user:
- Username: alice, bob, charlie
- Email: alice@example.com, etc.
- Password: password
5. Update .env¶
OIDC_CLIENT_ID=webapp
OIDC_CLIENT_SECRET=<from provider>
OIDC_ISSUER=http://authentik-server:9000/application/o/webapp/
6. Restart Webapp¶
Terraform Configuration¶
Provider Setup¶
File: terraform/authentik-webapp/providers.tf
terraform {
required_providers {
authentik = {
source = "goauthentik/authentik"
version = "~> 2024.0"
}
}
}
provider "authentik" {
url = "http://localhost:9000"
token = var.authentik_token
}
Add Users¶
File: terraform/authentik-webapp/variables.tf
variable "test_users" {
default = [
{
username = "alice"
name = "Alice Smith"
email = "alice@example.com"
password = "password"
},
{
username = "bob"
name = "Bob Jones"
email = "bob@example.com"
password = "password"
},
]
}
Apply changes:
Bootstrap Token¶
The bootstrap token enables Terraform API access:
# env.authentik
AUTHENTIK_BOOTSTRAP_TOKEN=changeme-bootstrap-token
AUTHENTIK_BOOTSTRAP_PASSWORD=adminpass
Terraform uses this token:
Troubleshooting¶
Cannot connect to Authentik¶
Token invalid¶
Reset Authentik¶
Security Notes¶
For production: 1. Generate strong random secrets 2. Enable HTTPS 3. Use environment variable injection 4. Rotate bootstrap token 5. Restrict admin access
See Also¶
- Setup Tutorial - Complete setup
- Authentication Tutorial - SSO flow
- SSO Concepts - OIDC architecture