Skip to content

Commit e86b6fd

Browse files
committed
feat: oidc
1 parent cf61685 commit e86b6fd

3 files changed

Lines changed: 147 additions & 16 deletions

File tree

.vitepress/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export default defineConfig({
5454
],
5555
},
5656
{
57-
text: 'Miscellaneous',
57+
text: 'Guides',
5858
items: [
59+
{text: 'OpenID Connect (OIDC)', link: '/docs/oidc'},
5960
{text: 'Apache reverse proxy', link: '/docs/apache'},
6061
{text: 'Caddy 2 reverse proxy', link: '/docs/caddy'},
6162
{text: 'Haproxy reverse proxy', link: '/docs/haproxy'},

docs/config.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,46 @@ server:
4040
enabled: false # if the certificate should be requested from letsencrypt
4141
accepttos: false # if you accept the tos from letsencrypt
4242
cache: data/certs # the directory of the cache from letsencrypt
43+
directoryurl: # override the directory url of the ACME server
44+
# Let's Encrypt highly recommend testing against their staging environment before using their production environment.
45+
# Staging server has high rate limits for testing and debugging, issued certificates are not valid
46+
# example: https://acme-staging-v02.api.letsencrypt.org/directory
4347
hosts: # the hosts for which letsencrypt should request certificates
44-
# - mydomain.tld
45-
# - myotherdomain.tld
48+
# - mydomain.tld
49+
# - myotherdomain.tld
4650
responseheaders: # response headers are added to every response (default: none)
47-
# X-Custom-Header: "custom value"
51+
# X-Custom-Header: "custom value"
52+
4853
trustedproxies: # IPs or IP ranges of trusted proxies. Used to obtain the remote ip via the X-Forwarded-For header. (configure 127.0.0.1 to trust sockets)
49-
# - 127.0.0.1
50-
# - 192.168.178.0/24
54+
# - 127.0.0.1/32
5155
# - ::1
56+
securecookie: false # If the secure flag should be set on cookies. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#secure
5257

5358
cors: # Sets cors headers only when needed and provides support for multiple allowed origins. Overrides Access-Control-* Headers in response headers.
5459
alloworigins:
55-
# - ".+.example.com"
56-
# - "otherdomain.com"
60+
# - ".+.example.com"
61+
# - "otherdomain.com"
5762
allowmethods:
58-
# - "GET"
59-
# - "POST"
63+
# - "GET"
64+
# - "POST"
6065
allowheaders:
61-
# - "Authorization"
62-
# - "content-type"
63-
66+
# - "Authorization"
67+
# - "content-type"
6468
stream:
6569
pingperiodseconds: 45 # the interval in which websocket pings will be sent. Only change this value if you know what you are doing.
66-
allowedorigins: # allowed origins for websocket connections (same origin is always allowed, default only same origin)
70+
allowedorigins: # allowed origins for websocket connections (same origin is always allowed)
6771
# - ".+.example.com"
6872
# - "otherdomain.com"
69-
database: # see below
73+
oidc:
74+
enabled: false # Enable OpenID Connect login, allowing users to authenticate via an external identity provider (e.g. Keycloak, Authelia, Google).
75+
issuer: # The OIDC issuer URL. This is the base URL of your identity provider, used to discover endpoints. Example: "https://auth.example.com/realms/myrealm"
76+
clientid: # The client ID registered with your identity provider for this application.
77+
clientsecret: # The client secret for the registered client.
78+
redirecturl: http://gotify.example.org/auth/oidc/callback # The callback URL that the identity provider redirects to after authentication. Must match exactly what is configured in your identity provider.
79+
autoregister: true # If true, automatically create a new user on first OIDC login. If false, only existing users can log in via OIDC.
80+
usernameclaim: preferred_username # The OIDC claim used to determine the username. Common values: "preferred_username" or "email".
81+
82+
database: # for database see (configure database section)
7083
dialect: sqlite3
7184
connection: data/gotify.db
7285
defaultuser: # on database creation, gotify creates an admin user (these values will only be used for the first start, if you want to edit the user after the first start use the WebUI)
@@ -118,7 +131,8 @@ GOTIFY_SERVER_SSL_CERTFILE=
118131
GOTIFY_SERVER_SSL_CERTKEY=
119132
GOTIFY_SERVER_SSL_LETSENCRYPT_ENABLED=false
120133
GOTIFY_SERVER_SSL_LETSENCRYPT_ACCEPTTOS=false
121-
GOTIFY_SERVER_SSL_LETSENCRYPT_CACHE=certs
134+
GOTIFY_SERVER_SSL_LETSENCRYPT_CACHE=data/certs
135+
GOTIFY_SERVER_SSL_LETSENCRYPT_DIRECTORYURL=
122136
# GOTIFY_SERVER_SSL_LETSENCRYPT_HOSTS=[mydomain.tld, myotherdomain.tld]
123137
# GOTIFY_SERVER_RESPONSEHEADERS={X-Custom-Header: "custom value", x-other: value}
124138
# GOTIFY_SERVER_TRUSTEDPROXIES=[127.0.0.1,192.168.178.2/24]
@@ -127,6 +141,7 @@ GOTIFY_SERVER_SSL_LETSENCRYPT_CACHE=certs
127141
# GOTIFY_SERVER_CORS_ALLOWHEADERS=[X-Gotify-Key, Authorization]
128142
# GOTIFY_SERVER_STREAM_ALLOWEDORIGINS=[.+.example\.com, otherdomain\.com]
129143
GOTIFY_SERVER_STREAM_PINGPERIODSECONDS=45
144+
GOTIFY_SERVER_SECURECOOKIE=false
130145
GOTIFY_DATABASE_DIALECT=sqlite3
131146
GOTIFY_DATABASE_CONNECTION=data/gotify.db
132147
GOTIFY_DEFAULTUSER_NAME=admin
@@ -135,4 +150,11 @@ GOTIFY_PASSSTRENGTH=10
135150
GOTIFY_UPLOADEDIMAGESDIR=data/images
136151
GOTIFY_PLUGINSDIR=data/plugins
137152
GOTIFY_REGISTRATION=false
153+
GOTIFY_OIDC_ENABLED=false
154+
GOTIFY_OIDC_ISSUER=
155+
GOTIFY_OIDC_CLIENTID=
156+
GOTIFY_OIDC_CLIENTSECRET=
157+
GOTIFY_OIDC_REDIRECTURL=http://gotify.example.org/auth/oidc/callback
158+
GOTIFY_OIDC_AUTOREGISTER=true
159+
GOTIFY_OIDC_USERNAMECLAIM=preferred_username
138160
```

docs/oidc.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# OpenID Connect (OIDC)
2+
3+
[[toc]]
4+
5+
Gotify supports OpenID Connect for Single Sign-On (SSO), allowing users to authenticate via an external identity provider such as Authelia or Dex.
6+
7+
::: warning
8+
The identity provider **must** support [PKCE](https://oauth.net/2/pkce/) (Proof Key for Code Exchange). IdPs without PKCE support are currently unsupported.
9+
:::
10+
11+
## Configuration
12+
13+
| Variable | Description |
14+
| :----------------------------- | :--------------------------------------------------------------------------------------------------------- |
15+
| `GOTIFY_OIDC_ENABLED` | Enable OIDC login. |
16+
| `GOTIFY_OIDC_ISSUER` | The OIDC issuer URL. Used to discover endpoints via `/.well-known/openid-configuration`. |
17+
| `GOTIFY_OIDC_CLIENTID` | The client ID registered with your identity provider. |
18+
| `GOTIFY_OIDC_CLIENTSECRET` | The client secret. |
19+
| `GOTIFY_OIDC_REDIRECTURL` | The callback URL the identity provider redirects to after authentication. Must match your provider config. |
20+
| `GOTIFY_OIDC_AUTOREGISTER` | Automatically create a new Gotify user on first OIDC login. |
21+
| `GOTIFY_OIDC_USERNAMECLAIM` | The OIDC claim used to determine the username. Common values: `preferred_username` or `email`. |
22+
| `GOTIFY_OIDC_LINK_BY_USERNAME` | Link an OIDC identity to an existing local user with the same username. Disabled by default. |
23+
| `GOTIFY_OIDC_SCOPES` | Comma-separated scopes to request. Defaults to `openid,profile,email`. |
24+
25+
```bash
26+
GOTIFY_OIDC_ENABLED=true
27+
GOTIFY_OIDC_ISSUER=https://auth.example.org
28+
GOTIFY_OIDC_CLIENTID=gotify
29+
GOTIFY_OIDC_CLIENTSECRET=YOUR_CLIENT_SECRET
30+
GOTIFY_OIDC_REDIRECTURL=https://gotify.example.org/auth/oidc/callback
31+
GOTIFY_OIDC_AUTOREGISTER=true
32+
GOTIFY_OIDC_USERNAMECLAIM=preferred_username
33+
GOTIFY_OIDC_LINK_BY_USERNAME=false
34+
GOTIFY_OIDC_SCOPES=openid,profile,email
35+
```
36+
37+
See the [Configuration](/docs/config) page for the full config reference.
38+
39+
### Redirect URL
40+
41+
- The redirect URL must always end with `/auth/oidc/callback`.
42+
- If Gotify is served at the root, the redirect URL is `https://gotify.example.org/auth/oidc/callback`.
43+
- If Gotify is served on a sub-path (e.g. behind a reverse proxy at `/gotify/`), the sub-path must be included: `https://example.org/gotify/auth/oidc/callback`.
44+
- For the **Android app** to support OIDC login, you must add `gotify://oidc/callback` as an additional redirect URL in your identity provider's client configuration.
45+
46+
This URL must match **exactly** between the Gotify config and your identity provider's client configuration.
47+
48+
## Linking by username
49+
50+
Gotify identifies users by username. When the OIDC username claim clashes with an existing local user that is not yet bound to an OIDC identity, this login is rejected by default. Set `GOTIFY_OIDC_LINK_BY_USERNAME=true` to bind OIDC identities to existing local users.
51+
52+
Only enable it if you trust that usernames in your identity provider map to the same people as your Gotify usernames.
53+
54+
## Sample IdP Config
55+
56+
### Authelia
57+
58+
[Authelia](https://www.authelia.com/) is a self-hosted authentication and authorization server.
59+
60+
::: details Authelia configuration (configuration.yml)
61+
62+
```yml
63+
identity_providers:
64+
oidc:
65+
clients:
66+
- client_id: 'gotify'
67+
client_name: 'gotify'
68+
client_secret: '$pbkdf2-sha512$310000$...' # generate with: authelia crypto hash generate pbkdf2
69+
public: false
70+
authorization_policy: 'two_factor'
71+
require_pkce: true
72+
pkce_challenge_method: 'S256'
73+
consent_mode: implicit
74+
redirect_uris:
75+
- 'https://gotify.example.org/auth/oidc/callback' # See redirect url docs
76+
- 'gotify://oidc/callback' # Required for Android app OIDC login
77+
scopes:
78+
- 'openid'
79+
- 'profile'
80+
- 'email'
81+
response_types:
82+
- 'code'
83+
grant_types:
84+
- 'authorization_code'
85+
access_token_signed_response_alg: 'none'
86+
userinfo_signed_response_alg: 'none'
87+
token_endpoint_auth_method: 'client_secret_basic'
88+
```
89+
90+
:::
91+
92+
### Dex
93+
94+
[Dex](https://dexidp.io/) is a federated OpenID Connect provider.
95+
96+
::: details Dex configuration
97+
98+
```yml
99+
staticClients:
100+
- id: gotify
101+
redirectURIs:
102+
- 'https://gotify.example.org/auth/oidc/callback' # See redirect url docs
103+
- 'gotify://oidc/callback' # Required for Android app OIDC login
104+
name: 'Gotify'
105+
secret: secret
106+
```
107+
108+
:::

0 commit comments

Comments
 (0)