Skip to content

Commit 4402b25

Browse files
committed
Document the new usptream OAuth 2.0 configuration options
1 parent afc3ae7 commit 4402b25

File tree

3 files changed

+107
-7
lines changed

3 files changed

+107
-7
lines changed

crates/handlers/src/upstream_oauth2/template.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ use minijinja::{
1515
/// Context passed to the attribute mapping template
1616
///
1717
/// The variables available in the template are:
18-
/// - `user`: claims for the user, currently from the ID token. Later, we'll
19-
/// also allow importing from the userinfo endpoint
18+
/// - `user`: claims for the user, merged from the ID token and userinfo
19+
/// endpoint
2020
/// - `id_token_claims`: claims from the ID token
21+
/// - `userinfo_claims`: claims from the userinfo endpoint
2122
/// - `extra_callback_parameters`: extra parameters passed to the callback
2223
#[derive(Debug, Default)]
2324
pub(crate) struct AttributeMappingContext {

docs/reference/configuration.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ upstream_oauth2:
538538
# The issuer URL, which will be used to discover the provider's configuration.
539539
# If discovery is enabled, this *must* exactly match the `issuer` field
540540
# advertised in `<issuer>/.well-known/openid-configuration`.
541-
issuer: https://example.com/
541+
# It must be set if OIDC discovery is enabled (which is the default).
542+
#issuer: https://example.com/
542543

543544
# A human-readable name for the provider,
544545
# which will be displayed on the login page
@@ -569,8 +570,19 @@ upstream_oauth2:
569570
# - `client_secret_post`
570571
# - `client_secret_jwt`
571572
# - `private_key_jwt` (using the keys defined in the `secrets.keys` section)
573+
# - `sign_in_with_apple` (a special authentication method for Sign-in with Apple)
572574
token_endpoint_auth_method: client_secret_post
573575

576+
# Additional paramaters for the `sign_in_with_apple` authentication method
577+
# See https://www.oauth.com/oauth2-servers/pkce/authorization-code-flow-with-pkce/
578+
#sign_in_with_apple:
579+
# private_key: |
580+
# -----BEGIN PRIVATE KEY-----
581+
# ...
582+
# -----END PRIVATE KEY-----
583+
# team_id: "<team-id>"
584+
# key_id: "<key-id>"
585+
574586
# Which signing algorithm to use to sign the authentication request when using
575587
# the `private_key_jwt` or the `client_secret_jwt` authentication methods
576588
#token_endpoint_auth_signing_alg: RS256
@@ -595,6 +607,19 @@ upstream_oauth2:
595607
# - `never`: never use PKCE
596608
#pkce_method: auto
597609

610+
# Whether to fetch user claims from the userinfo endpoint
611+
# This is disabled by default, as most providers will return the necessary
612+
# claims in the `id_token`
613+
#fetch_userinfo: true
614+
615+
# If set, ask for a signed response on the userinfo endpoint, and validate
616+
# the response uses the given algorithm
617+
#userinfo_endpoint_auth_signing_alg: RS256
618+
619+
# The userinfo endpoint
620+
# This takes precedence over the discovery mechanism
621+
#userinfo_endpoint: https://example.com/oauth2/userinfo
622+
598623
# The provider authorization endpoint
599624
# This takes precedence over the discovery mechanism
600625
#authorization_endpoint: https://example.com/oauth2/authorize
@@ -607,6 +632,10 @@ upstream_oauth2:
607632
# This takes precedence over the discovery mechanism
608633
#jwks_uri: https://example.com/oauth2/keys
609634

635+
# Additional parameters to include in the authorization request
636+
#additional_authorization_parameters:
637+
# foo: "bar"
638+
610639
# How user attributes should be mapped
611640
#
612641
# Most of those attributes have two main properties:
@@ -617,7 +646,8 @@ upstream_oauth2:
617646
# - `require`: always import the attribute, and fail if it's missing
618647
# - `template`: a Jinja2 template used to generate the value. In this template,
619648
# the `user` variable is available, which contains the user's attributes
620-
# retrieved from the `id_token` given by the upstream provider.
649+
# retrieved from the `id_token` given by the upstream provider and/or through
650+
# the userinfo endpoint.
621651
#
622652
# Each attribute has a default template which follows the well-known OIDC claims.
623653
#
@@ -654,6 +684,11 @@ upstream_oauth2:
654684
# - `always`: mark the email address as verified
655685
# - `never`: mark the email address as not verified
656686
#set_email_verification: import
687+
688+
# An account name, for display purposes only
689+
# This helps end user identify what account they are using
690+
account_name:
691+
#template: "@{{ user.preferred_username }}"
657692
```
658693

659694
## `experimental`

docs/setup/sso.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The authentication service supports importing the following user attributes from
4040
- The localpart/username (e.g. `@localpart:example.com`)
4141
- The display name
4242
- An email address
43+
- An account name, to help end users identify what account they are using
4344

4445
For each of those attributes, administrators can configure a mapping using the claims provided by the upstream provider.
4546
They can also configure what should be done for each of those attributes. It can either:
@@ -49,12 +50,20 @@ They can also configure what should be done for each of those attributes. It can
4950
- `force`: automatically import the attribute, but don't fail if it is not provided by the provider
5051
- `require`: automatically import the attribute, and fail if it is not provided by the provider
5152

52-
A Jinja2 template is used as mapping for each attribute. The template currently has one `user` variable, which is an object with the claims got through the `id_token` given by the provider.
53+
A Jinja2 template is used as mapping for each attribute.
5354
The following default templates are used:
5455

5556
- `localpart`: `{{ user.preferred_username }}`
5657
- `displayname`: `{{ user.name }}`
5758
- `email`: `{{ user.email }}`
59+
- `account_name`: none
60+
61+
The template has the following variables available:
62+
63+
- `id_token_claims`: an object with the claims got through the `id_token` given by the provider, if provided by the provider
64+
- `userinfo_claims`: an object with the claims got through the `userinfo` endpoint, if `fetch_userinfo` is enabled
65+
- `user`: an object which contains the claims from both the `id_token` and the `userinfo` endpoint
66+
- `extra_callback_parameters`: an object with the additional parameters the provider sent to the redirect URL
5867

5968
## Multiple providers behaviour
6069

@@ -95,10 +104,14 @@ upstream_oauth2:
95104
# SiWA passes down the user infos as query parameters in the callback
96105
# which is available in the extra_callback_parameters variable
97106
template: |
98-
{%- set user = extra_callback_parameters["user"] | from_json -%}
99-
{{- user.name.firstName }} {{ user.name.lastName -}}
107+
{%- set u = extra_callback_parameters["user"] | from_json -%}
108+
{{- u.name.firstName }} {{ u.name.lastName -}}
100109
email:
101110
action: suggest
111+
account_name:
112+
template: |
113+
{%- set u = extra_callback_parameters["user"] | from_json -%}
114+
{{- u.name.firstName }} {{ u.name.lastName -}}
102115
```
103116
104117
### Authelia
@@ -230,6 +243,8 @@ upstream_oauth2:
230243
action: suggest
231244
template: "{{ user.email }}"
232245
set_email_verification: always
246+
account_name:
247+
template: "{{ user.name }}"
233248
```
234249

235250

@@ -261,6 +276,51 @@ upstream_oauth2:
261276
email:
262277
action: suggest
263278
template: "{{ user.email }}"
279+
account_name:
280+
template: "@{{ user.preferred_username }}"
281+
```
282+
283+
### GitHub
284+
285+
GitHub doesn't support OpenID Connect, but it does support OAuth 2.0.
286+
It will use the `fetch_userinfo` option with a manual `userinfo_endpoint` to fetch the user's profile through the GitHub API.
287+
288+
1. Create a [new application](https://github.com/settings/applications/new).
289+
2. Fill in the form with an application name and homepage URL.
290+
3. Use the following Authorization callback URL: `https://<auth-service-domain>/upstream/callback/<id>`
291+
4. Retrieve the Client ID
292+
5. Generate a Client Secret and copy it
293+
294+
Authentication service configuration:
295+
296+
```yaml
297+
upstream_oauth2:
298+
providers:
299+
- id: "01HFS67GJ145HCM9ZASYS9DC3J"
300+
human_name: GitHub
301+
brand_name: github
302+
discovery_mode: disabled
303+
fetch_userinfo: true
304+
token_endpoint_auth_method: "client_secret_post"
305+
client_id: "<client-id>" # TO BE FILLED
306+
client_secret: "<client-secret>" # TO BE FILLED
307+
authorization_endpoint: "https://github.com/login/oauth/authorize"
308+
token_endpoint: "https://github.com/login/oauth/access_token"
309+
userinfo_endpoint: "https://api.github.com/user"
310+
scope: "read:user"
311+
claims_imports:
312+
subject:
313+
template: "{{ userinfo_claims.id }}"
314+
displayname:
315+
action: suggest
316+
template: "{{`{{ userinfo_claims.name }}"
317+
localpart:
318+
action: ignore
319+
email:
320+
action: suggest
321+
template: "{{ userinfo_claims.email }}"
322+
account_name:
323+
template: "@{{ userinfo_claims.login }}"
264324
```
265325
266326
@@ -291,6 +351,8 @@ upstream_oauth2:
291351
email:
292352
action: suggest
293353
template: "{{ user.email }}"
354+
account_name:
355+
template: "{{ user.email }}"
294356
```
295357

296358

@@ -384,4 +446,6 @@ upstream_oauth2:
384446
action: suggest
385447
template: "{{ user.email }}"
386448
set_email_verification: always
449+
account_name:
450+
template: "{{ user.preferred_username }}"
387451
```

0 commit comments

Comments
 (0)