Skip to content

Commit 5562334

Browse files
authored
Add OIDC authentication configuration documentation (#46)
* Add OIDC authentication configuration documentation Documents OIDC setup including custom providers, built-in providers (Google, Microsoft, GitHub), and configuration examples with comprehensive setting descriptions. * Document missing OIDC configuration variables and role mapping - Add OIDC_USERNAME_CLAIM and OIDC_OPENID_CONFIG_URL to base config table - Add complete OIDC Role Mapping section documenting: - OIDC_ROLE_CLAIM for customizing the claim name - OIDC_GROUP_* variables for mapping provider groups to Gramps roles - Add role mapping example to OIDC configuration example - Include notes on role mapping behavior and case sensitivity * Add OIDC logout and backchannel logout documentation - Document OIDC Single Sign-Out (SSO logout) functionality - Add comprehensive backchannel logout setup instructions - Include provider-specific configuration for Keycloak and Authentik - Explain token expiration limitations and security considerations - Add step-by-step guide for registering backchannel logout endpoint * add redirect URI instructions * Reorganize OIDC documentation into dedicated page Create separate OIDC authentication page with setup instructions and examples, while keeping settings reference in configuration page. * Convert OIDC variable lists to table format for consistency Updates oidc.md to use table format for Custom OIDC Providers and Role Mapping configuration variables, matching the style used in configuration.md. Also improves variable descriptions for clarity and adds spacing for proper list rendering. * fix info and warn boxes
1 parent 6158fe0 commit 5562334

File tree

3 files changed

+249
-6
lines changed

3 files changed

+249
-6
lines changed

docs/install_setup/configuration.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following configuration options exist.
2727

2828
### Required settings
2929

30-
Key | Description
30+
Key | Description
3131
----|-------------
3232
`TREE` | The name of the family tree database to use. Show available trees with `gramps -l`. If a tree with this name does not exist, a new empty one will be created.
3333
`SECRET_KEY` | The secret key for flask. The secret must not be shared publicly. Changing it will invalidate all access tokens.
@@ -42,7 +42,7 @@ Key | Description
4242

4343
### Optional settings
4444

45-
Key | Description
45+
Key | Description
4646
----|-------------
4747
`MEDIA_BASE_DIR` | Path to use as base directory for media files, overriding the media base directory set in Gramps. When using [S3](s3.md), must have the form `s3://<bucket_name>`
4848
`SEARCH_INDEX_DB_URI` | Database URL for the search index. Only `sqlite` or `postgresql` are allowed as backends. Defaults to `sqlite:///indexdir/search_index.db`, creating an SQLite file in the folder `indexdir` relative to the path where the script is run
@@ -73,7 +73,7 @@ Key | Description
7373

7474
This is required if you've configured your Gramps database to work with the [PostgreSQL addon](https://gramps-project.org/wiki/index.php/Addon:PostgreSQL).
7575

76-
Key | Description
76+
Key | Description
7777
----|-------------
7878
`POSTGRES_USER` | The user name for the database connection
7979
`POSTGRES_PASSWORD` | The password for the database user
@@ -84,19 +84,63 @@ Key | Description
8484
The following settings are relevant when [hosting multiple trees](multi-tree.md).
8585

8686

87-
Key | Description
87+
Key | Description
8888
----|-------------
8989
`MEDIA_PREFIX_TREE` | Boolean, whether or not to use a separate subfolder for the media files of each tree. Defaults to `False`, but strongly recommend to use `True` in a multi-tree setup
9090
`NEW_DB_BACKEND` | The database backend to use for newly created family trees. Must be one of `sqlite`, `postgresql`, or `sharedpostgresql`. Defaults to `sqlite`.
9191
`POSTGRES_HOST` | The host name of the PostgreSQL server used for creating new trees when using a multi-tree setup with the SharedPostgreSQL backend
9292
`POSTGRES_PORT` | The port of the PostgreSQL server used for creating new trees when using a multi-tree setup with the SharedPostgreSQL backend
9393

94-
94+
95+
### Settings for OIDC authentication
96+
97+
These settings are needed if you want to use OpenID Connect (OIDC) authentication with external providers. For detailed setup instructions and examples, see [OIDC Authentication](oidc.md).
98+
99+
Key | Description
100+
----|-------------
101+
`OIDC_ENABLED` | Boolean, whether to enable OIDC authentication. Defaults to `False`.
102+
`OIDC_ISSUER` | OIDC provider issuer URL (for custom OIDC providers)
103+
`OIDC_CLIENT_ID` | OAuth client ID (for custom OIDC providers)
104+
`OIDC_CLIENT_SECRET` | OAuth client secret (for custom OIDC providers)
105+
`OIDC_NAME` | Custom display name for the provider. Defaults to "OIDC"
106+
`OIDC_SCOPES` | OAuth scopes. Defaults to "openid email profile"
107+
`OIDC_USERNAME_CLAIM` | The claim to use for the username. Defaults to "preferred_username"
108+
`OIDC_OPENID_CONFIG_URL` | Optional: URL to the OpenID Connect configuration endpoint (if not using standard `/.well-known/openid-configuration`)
109+
`OIDC_DISABLE_LOCAL_AUTH` | Boolean, whether to disable local username/password authentication. Defaults to `False`
110+
`OIDC_AUTO_REDIRECT` | Boolean, whether to automatically redirect to OIDC when only one provider is configured. Defaults to `False`
111+
112+
#### Built-in OIDC providers
113+
114+
For built-in providers (Google, Microsoft, GitHub), use these settings:
115+
116+
Key | Description
117+
----|-------------
118+
`OIDC_GOOGLE_CLIENT_ID` | Client ID for Google OAuth
119+
`OIDC_GOOGLE_CLIENT_SECRET` | Client secret for Google OAuth
120+
`OIDC_MICROSOFT_CLIENT_ID` | Client ID for Microsoft OAuth
121+
`OIDC_MICROSOFT_CLIENT_SECRET` | Client secret for Microsoft OAuth
122+
`OIDC_GITHUB_CLIENT_ID` | Client ID for GitHub OAuth
123+
`OIDC_GITHUB_CLIENT_SECRET` | Client secret for GitHub OAuth
124+
125+
#### OIDC Role Mapping
126+
127+
These settings allow you to map OIDC groups/roles from your identity provider to Gramps Web user roles:
128+
129+
Key | Description
130+
----|-------------
131+
`OIDC_ROLE_CLAIM` | The claim name in the OIDC token that contains the user's groups/roles. Defaults to "groups"
132+
`OIDC_GROUP_ADMIN` | The group/role name from your OIDC provider that maps to the Gramps "Admin" role
133+
`OIDC_GROUP_OWNER` | The group/role name from your OIDC provider that maps to the Gramps "Owner" role
134+
`OIDC_GROUP_EDITOR` | The group/role name from your OIDC provider that maps to the Gramps "Editor" role
135+
`OIDC_GROUP_CONTRIBUTOR` | The group/role name from your OIDC provider that maps to the Gramps "Contributor" role
136+
`OIDC_GROUP_MEMBER` | The group/role name from your OIDC provider that maps to the Gramps "Member" role
137+
`OIDC_GROUP_GUEST` | The group/role name from your OIDC provider that maps to the Gramps "Guest" role
138+
95139
### Settings only for AI features
96140

97141
These settings are needed if you want to use AI-powered features like chat or semantic search.
98142

99-
Key | Description
143+
Key | Description
100144
----|-------------
101145
`LLM_BASE_URL` | Base URL for the OpenAI-compatible chat API. Defaults to `None`, which uses the OpenAI API.
102146
`LLM_MODEL` | The model to use for the OpenAI-compatible chat API. If unset (the default), chat is disabled.

docs/install_setup/oidc.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# OIDC Authentication
2+
3+
Gramps Web supports OpenID Connect (OIDC) authentication, allowing users to log in using external identity providers. This includes both popular providers like Google, Microsoft, and GitHub, as well as custom OIDC providers like Keycloak, Authentik, and others.
4+
5+
## Overview
6+
7+
OIDC authentication allows you to:
8+
9+
- Use external identity providers for user authentication
10+
- Support multiple authentication providers simultaneously
11+
- Map OIDC groups/roles to Gramps Web user roles
12+
- Implement Single Sign-On (SSO) and Single Sign-Out
13+
- Optionally disable local username/password authentication
14+
15+
## Configuration
16+
17+
To enable OIDC authentication, you need to configure the appropriate settings in your Gramps Web configuration file or environment variables. See the [Server Configuration](configuration.md#settings-for-oidc-authentication) page for a complete list of available OIDC settings.
18+
19+
!!! info
20+
When using environment variables, remember to prefix each setting name with `GRAMPSWEB_` (e.g., `GRAMPSWEB_OIDC_ENABLED`). See [Configuration file vs. environment variables](configuration.md#configuration-file-vs-environment-variables) for details.
21+
22+
### Built-in Providers
23+
24+
Gramps Web has built-in support for popular identity providers. To use them, you only need to provide the client ID and client secret:
25+
26+
- **Google**: `OIDC_GOOGLE_CLIENT_ID` and `OIDC_GOOGLE_CLIENT_SECRET`
27+
- **Microsoft**: `OIDC_MICROSOFT_CLIENT_ID` and `OIDC_MICROSOFT_CLIENT_SECRET`
28+
- **GitHub**: `OIDC_GITHUB_CLIENT_ID` and `OIDC_GITHUB_CLIENT_SECRET`
29+
30+
You can configure multiple providers simultaneously. The system will automatically detect which providers are available based on the configuration values.
31+
32+
### Custom OIDC Providers
33+
34+
For custom OIDC providers (like Keycloak, Authentik, or any standard OIDC-compliant provider), use these settings:
35+
36+
Key | Description
37+
----|-------------
38+
`OIDC_ENABLED` | Boolean, whether to enable OIDC authentication. Set to `True`.
39+
`OIDC_ISSUER` | Your provider's issuer URL
40+
`OIDC_CLIENT_ID` | Client ID for your OIDC provider
41+
`OIDC_CLIENT_SECRET` | Client secret for your OIDC provider
42+
`OIDC_NAME` | Custom display name (optional, defaults to "OIDC")
43+
`OIDC_SCOPES` | OAuth scopes (optional, defaults to "openid email profile")
44+
45+
## Required Redirect URIs
46+
47+
When configuring your OIDC provider, you must register the following redirect URI:
48+
49+
**For web application access:**
50+
51+
- `https://your-gramps-backend.com/api/oidc/callback/*`
52+
53+
Where `*` is a regex wildcard. Depending on your provider's regex interpreter this could also be a `.*` or similar.
54+
Ensure that regex is enabled if your provider requires it (e.g., Authentik).
55+
56+
57+
## Role Mapping
58+
59+
Gramps Web can automatically map OIDC groups or roles from your identity provider to Gramps Web user roles. This allows you to manage user permissions centrally in your identity provider.
60+
61+
### Configuration
62+
63+
Use these settings to configure role mapping:
64+
65+
Key | Description
66+
----|-------------
67+
`OIDC_ROLE_CLAIM` | The claim name in the OIDC token that contains the user's groups/roles. Defaults to "groups"
68+
`OIDC_GROUP_ADMIN` | The group/role name from your OIDC provider that maps to the Gramps "Admin" role
69+
`OIDC_GROUP_OWNER` | The group/role name from your OIDC provider that maps to the Gramps "Owner" role
70+
`OIDC_GROUP_EDITOR` | The group/role name from your OIDC provider that maps to the Gramps "Editor" role
71+
`OIDC_GROUP_CONTRIBUTOR` | The group/role name from your OIDC provider that maps to the Gramps "Contributor" role
72+
`OIDC_GROUP_MEMBER` | The group/role name from your OIDC provider that maps to the Gramps "Member" role
73+
`OIDC_GROUP_GUEST` | The group/role name from your OIDC provider that maps to the Gramps "Guest" role
74+
75+
### Role Mapping Behavior
76+
77+
- If no role mapping is configured (no `OIDC_GROUP_*` variables set), existing user roles are preserved
78+
- Users are assigned the highest role they are entitled to based on their group membership
79+
- Role mapping is case-sensitive by default (depends on your OIDC provider)
80+
81+
## OIDC Logout
82+
83+
Gramps Web supports Single Sign-Out (SSO logout) for OIDC providers. When a user logs out from Gramps Web after authenticating via OIDC, they will be automatically redirected to the identity provider's logout page if the provider supports the `end_session_endpoint`.
84+
85+
### Backchannel Logout
86+
87+
Gramps Web implements the OpenID Connect Back-Channel Logout specification. This allows identity providers to notify Gramps Web when a user logs out from another application or the identity provider itself.
88+
89+
#### Configuration
90+
91+
To configure backchannel logout with your identity provider:
92+
93+
1. **Register the backchannel logout endpoint** in your identity provider's client configuration:
94+
```
95+
https://your-gramps-backend.com/api/oidc/backchannel-logout/
96+
```
97+
98+
2. **Configure your provider** to send logout notifications. The exact steps depend on your provider:
99+
100+
**Keycloak:**
101+
102+
- In your client configuration, navigate to "Settings"
103+
- Set "Backchannel Logout URL" to `https://your-gramps-backend.com/api/oidc/backchannel-logout/`
104+
- Enable "Backchannel Logout Session Required" if you want session-based logout
105+
106+
**Authentik:**
107+
108+
- In your provider configuration, add the backchannel logout URL
109+
- Ensure the provider is configured to send logout tokens
110+
111+
!!! warning "Token Expiration"
112+
Due to the stateless nature of JWT tokens, backchannel logout currently logs the logout event but cannot immediately revoke already-issued JWT tokens. Tokens will remain valid until they expire (default: 15 minutes for access tokens).
113+
114+
For enhanced security, consider:
115+
116+
- Reducing JWT token expiration time (`JWT_ACCESS_TOKEN_EXPIRES`)
117+
- Educating users to manually log out from Gramps Web when logging out from your identity provider
118+
119+
!!! tip "How It Works"
120+
When a user logs out from your identity provider or another application:
121+
122+
1. The provider sends a `logout_token` JWT to Gramps Web's backchannel logout endpoint
123+
2. Gramps Web validates the token and logs the logout event
124+
3. The logout token's JTI is added to a blocklist to prevent replay attacks
125+
4. Any new API requests with the user's JWT will be denied once tokens expire
126+
127+
## Example Configurations
128+
129+
### Custom OIDC Provider (Keycloak)
130+
131+
```python
132+
TREE="My Family Tree"
133+
BASE_URL="https://mytree.example.com"
134+
SECRET_KEY="..." # your secret key
135+
USER_DB_URI="sqlite:////path/to/users.sqlite"
136+
137+
# Custom OIDC Configuration
138+
OIDC_ENABLED=True
139+
OIDC_ISSUER="https://auth.example.com/realms/myrealm"
140+
OIDC_CLIENT_ID="gramps-web"
141+
OIDC_CLIENT_SECRET="your-client-secret"
142+
OIDC_NAME="Family SSO"
143+
OIDC_SCOPES="openid email profile"
144+
OIDC_AUTO_REDIRECT=True # Optional: automatically redirect to SSO login
145+
OIDC_DISABLE_LOCAL_AUTH=True # Optional: disable username/password login
146+
147+
# Optional: Role mapping from OIDC groups to Gramps roles
148+
OIDC_ROLE_CLAIM="groups" # or "roles" depending on your provider
149+
OIDC_GROUP_ADMIN="gramps-admins"
150+
OIDC_GROUP_EDITOR="gramps-editors"
151+
OIDC_GROUP_MEMBER="gramps-members"
152+
153+
EMAIL_HOST="mail.example.com"
154+
EMAIL_PORT=465
155+
EMAIL_USE_TLS=True
156+
EMAIL_HOST_USER="[email protected]"
157+
EMAIL_HOST_PASSWORD="..." # your SMTP password
158+
DEFAULT_FROM_EMAIL="[email protected]"
159+
```
160+
161+
### Built-in Provider (Google)
162+
163+
```python
164+
TREE="My Family Tree"
165+
BASE_URL="https://mytree.example.com"
166+
SECRET_KEY="..." # your secret key
167+
USER_DB_URI="sqlite:////path/to/users.sqlite"
168+
169+
# Google OAuth
170+
OIDC_GOOGLE_CLIENT_ID="your-google-client-id"
171+
OIDC_GOOGLE_CLIENT_SECRET="your-google-client-secret"
172+
```
173+
174+
### Multiple Providers
175+
176+
You can enable multiple OIDC providers simultaneously:
177+
178+
```python
179+
TREE="My Family Tree"
180+
BASE_URL="https://mytree.example.com"
181+
SECRET_KEY="..." # your secret key
182+
USER_DB_URI="sqlite:////path/to/users.sqlite"
183+
184+
# Custom provider
185+
OIDC_ENABLED=True
186+
OIDC_ISSUER="https://auth.example.com/realms/myrealm"
187+
OIDC_CLIENT_ID="gramps-web"
188+
OIDC_CLIENT_SECRET="your-client-secret"
189+
OIDC_NAME="Company SSO"
190+
191+
# Google OAuth
192+
OIDC_GOOGLE_CLIENT_ID="your-google-client-id"
193+
OIDC_GOOGLE_CLIENT_SECRET="your-google-client-secret"
194+
195+
# GitHub OAuth
196+
OIDC_GITHUB_CLIENT_ID="your-github-client-id"
197+
OIDC_GITHUB_CLIENT_SECRET="your-github-client-secret"
198+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ nav:
1212
- Server Administration:
1313
- User system: install_setup/users.md
1414
- Server configuration: install_setup/configuration.md
15+
- OIDC authentication: install_setup/oidc.md
1516
- Setting up AI chat: install_setup/chat.md
1617
- Multi-tree setup: install_setup/multi-tree.md
1718
- Frontend customization: install_setup/frontend-config.md

0 commit comments

Comments
 (0)