Skip to main content

tuwunel_core/config/
authentication.rs

1//! Configures account authentication and session lifetimes.
2//!
3//! Login, OIDC, password hashing, and refresh-token policy have dedicated
4//! settings. The integration secret authenticates MAS provisioning calls;
5//! the emergency password grants access to the server bot account.
6
7use serde::Deserialize;
8use tuwunel_macros::config_example_generator;
9
10use super::true_fn;
11
12/// Authentication and sessions
13///
14/// Server-wide credentials and token lifetimes, plus the sub-sections that
15/// decide how users sign in: `[global.authentication.login]` (accepted login
16/// methods and SSO presentation), `[global.authentication.oidc]` (the
17/// built-in OIDC server for next-generation clients),
18/// `[global.authentication.argon2]` (password-hash cost) and
19/// `[global.authentication.refresh_token]` (refresh-token expiry and reuse).
20/// The defaults suit a password-login server. Other sign-in sources have
21/// their own sections: `[[global.identity_provider]]`, `[global.jwt]` and
22/// `[global.ldap]`.
23///
24/// Tips:
25/// - Startup refuses an empty `emergency_password` and the example value
26///   shown below; while `ldap.enable` is true the emergency password is
27///   ignored with a warning.
28/// - `mas_secret` only authorizes Matrix Authentication Service provisioning
29///   calls under `/_synapse/mas/`. Signing in through MAS also needs an
30///   `[[global.identity_provider]]` entry with `brand = "MAS"`; startup warns
31///   when it is missing.
32/// - `access_token_ttl` applies only to sessions holding a refresh token (see
33///   `[global.authentication.refresh_token]`) and, under
34///   `jwt.expire_access_token`, to JWT logins.
35#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
36// No Debug: secrets are reachable from this section.
37#[derive(Clone, Deserialize)]
38#[config_example_generator(
39	filename = "tuwunel-example.toml",
40	section = "global.authentication",
41	group = "true",
42	ignore = "argon2 login oidc refresh_token"
43)]
44pub struct Authentication {
45	/// Authenticates Matrix Authentication Service provisioning calls with a
46	/// shared secret.
47	///
48	/// When set, the `/_synapse/mas/*` endpoints accept only requests bearing
49	/// this exact secret as their bearer token; when unset, they reject every
50	/// request. Use a high-entropy value identical to the secret configured in
51	/// MAS.
52	///
53	/// reloadable: yes
54	/// example: "kZ2hN5pQ8wXyL4mR7tBfCgJxV3aD6sE1u"
55	///
56	/// display: sensitive
57	/// legacy: mas_secret
58	pub mas_secret: Option<String>,
59
60	/// Sets the OpenID token lifetime in seconds.
61	///
62	/// These tokens primarily serve Matrix account integrations, such as
63	/// Vector Integrations in Element, rather than OIDC or OpenID Connect.
64	///
65	/// reloadable: yes
66	/// default: 3600
67	/// legacy: openid_token_ttl
68	#[serde(default = "default_openid_token_ttl")]
69	pub openid_token_ttl: u64,
70
71	/// Sets the access-token lifetime in seconds.
72	///
73	/// For clients supporting refresh tokens, the access token supplied at
74	/// login is invalidated after this interval, soft-logging out the client
75	/// until it refreshes. Under `jwt.expire_access_token`, a JWT login expires
76	/// the same way and needs a fresh JWT instead.
77	///
78	/// reloadable: yes
79	/// default: 604800
80	/// legacy: access_token_ttl
81	#[serde(default = "default_access_token_ttl")]
82	pub access_token_ttl: u64,
83
84	/// Allows emergency login to the server bot account, currently `@conduit`.
85	///
86	/// Use it for troubleshooting such as recovering or recreating the admin
87	/// room or inviting yourself back. Other recovery methods are described in
88	/// the [admin-room troubleshooting
89	/// guide](https://tuwunel.chat/troubleshooting.html#lost-access-to-admin-room).
90	/// Unsetting this password logs out all sessions for security.
91	///
92	/// example: "F670$2CP@Hw8mG7RY1$%!#Ic7YA"
93	///
94	/// display: sensitive
95	/// legacy: emergency_password
96	pub emergency_password: Option<String>,
97
98	/// Controls password-hashing memory, passes, and lanes.
99	///
100	/// display: section
101	#[serde(default)]
102	pub argon2: Argon2,
103
104	/// Controls supported login methods and provider selection.
105	///
106	/// display: section
107	#[serde(default)]
108	pub login: Login,
109
110	/// Controls native OIDC authorization and client registration.
111	///
112	/// display: section
113	#[serde(default)]
114	pub oidc: Oidc,
115
116	/// Controls refresh-token expiration and reuse.
117	///
118	/// display: section
119	#[serde(default)]
120	pub refresh_token: RefreshToken,
121}
122
123/// Password hashing cost
124///
125/// Sets the Argon2id cost used whenever a password is hashed. Existing hashes
126/// keep the cost they were created with until that password is next set, so
127/// a change takes effect gradually. The defaults follow the OWASP
128/// recommendation.
129///
130/// Tips:
131/// - Startup and reload refuse a combination Argon2 rejects, such as
132///   `m_cost` below eight blocks per lane of `p_cost`, and warn when the cost
133///   falls below the weakest OWASP pair listed under `m_cost`.
134#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
135#[derive(Clone, Copy, Debug, Deserialize)]
136#[config_example_generator(
137	filename = "tuwunel-example.toml",
138	section = "global.authentication.argon2",
139	group = "true"
140)]
141pub struct Argon2 {
142	/// Sets the Argon2id working-buffer size for hashing a new password, in 1
143	/// KiB blocks.
144	///
145	/// Each concurrent password operation retains roughly this much memory
146	/// for its duration, with no concurrency bound. Stored hashes retain their
147	/// parameters until the account's password is next set.
148	///
149	/// Lowering this weakens resistance to parallel cracking hardware unless
150	/// `authentication.argon2.t_cost` compensates; equivalent-strength
151	/// (`authentication.argon2.m_cost`, `authentication.argon2.t_cost`) pairs
152	/// are (47104, 1), (19456, 2), (12288, 3), (9216, 4), and (7168, 5). The
153	/// default and these pairs follow the [OWASP Argon2id
154	/// recommendation](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#argon2id).
155	///
156	/// reloadable: yes
157	/// default: 19456
158	/// legacy: argon2_m_cost
159	#[serde(default = "default_m_cost")]
160	pub m_cost: u32,
161
162	/// Sets the number of Argon2id passes over its working buffer.
163	///
164	/// Raising this increases CPU cost without changing memory cost. See
165	/// `authentication.argon2.m_cost` for equivalent-strength parameter pairs.
166	///
167	/// reloadable: yes
168	/// default: 2
169	/// legacy: argon2_t_cost
170	#[serde(default = "default_t_cost")]
171	pub t_cost: u32,
172
173	/// Sets the number of lanes in an Argon2id working buffer.
174	///
175	/// Lanes are computed sequentially here, so raising this changes the hash
176	/// without adding parallelism. `authentication.argon2.m_cost` must be at
177	/// least eight times this value.
178	///
179	/// reloadable: yes
180	/// default: 1
181	/// legacy: argon2_p_cost
182	#[serde(default = "default_p_cost")]
183	pub p_cost: u32,
184}
185
186/// Login methods
187///
188/// Chooses which login types `/_matrix/client/v3/login` advertises and
189/// accepts, how long login tokens last, and how clients present single
190/// sign-on providers. The defaults accept passwords and login tokens, and let
191/// a signed-in session mint a login token for another device.
192///
193/// Tips:
194/// - `with_password = false` also turns off `[global.ldap]` sign-in, which
195///   arrives as a password login, and refuses password registration.
196/// - JWT login is switched on by `jwt.enable`, not here; password attempt
197///   limits live in `[global.rate_limiting.login]`.
198#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
199#[derive(Clone, Copy, Debug, Deserialize)]
200#[config_example_generator(
201	filename = "tuwunel-example.toml",
202	section = "global.authentication.login",
203	group = "true"
204)]
205pub struct Login {
206	/// Allows an existing session to mint a login token for another client.
207	///
208	/// This requires interactive authentication and is enabled by default. A
209	/// malicious client could use it to spawn additional sessions, so enabling
210	/// it has security implications.
211	///
212	/// reloadable: yes
213	/// default: true
214	/// legacy: login_via_existing_session
215	#[serde(default = "true_fn")]
216	pub via_existing_session: bool,
217
218	/// Enables the login-token route to accept tokens.
219	///
220	/// The server can generate tokens for authorization flows such as SSO,
221	/// which disabling this may break. This differs from
222	/// `authentication.login.via_existing_session` and lacks that setting's
223	/// security implications: keep this enabled while disabling the other to
224	/// prevent clients from commanding token creation without preventing the
225	/// server from creating tokens.
226	///
227	/// reloadable: yes
228	/// default: true
229	/// legacy: login_via_token
230	#[serde(default = "true_fn")]
231	pub via_token: bool,
232
233	/// Enables traditional username-and-password login.
234	///
235	/// Disable this to allow only other mechanisms, such as SSO. Disabling it
236	/// also refuses password registration, at `/register` and on the native
237	/// OIDC login page, which then offers only the identity providers;
238	/// appservice and guest registration are unaffected.
239	///
240	/// reloadable: yes
241	/// default: true
242	/// legacy: login_with_password
243	#[serde(default = "true_fn")]
244	pub with_password: bool,
245
246	/// Sets the login-token lifetime in milliseconds.
247	///
248	/// These short-lived tokens serve `m.login.token`, allowing existing
249	/// sessions to create new sessions. See
250	/// `authentication.login.via_existing_session`.
251	///
252	/// reloadable: yes
253	/// default: 120000
254	/// legacy: login_token_ttl
255	#[serde(default = "default_token_ttl")]
256	pub token_ttl: u64,
257
258	/// Experimentally replaces the client login provider list with one "Sign
259	/// in with single sign-on" button.
260	///
261	/// The button links to `/_matrix/client/v3/login/sso/redirect`, attempting
262	/// every configured provider for the same Matrix user; every authorization
263	/// must succeed because providers cannot reliably be skipped. Disabled by
264	/// default, it otherwise lets clients list providers so privacy-conscious
265	/// users can authorize only their choice. For clients that already show
266	/// one button, use the provider configuration's `default` option instead.
267	///
268	/// reloadable: yes
269	/// legacy: single_sso
270	#[serde(default)]
271	pub single_sso: bool,
272
273	/// Replaces the client login provider list with one button for a custom
274	/// provider page.
275	///
276	/// The "Sign in with single sign-on" button links to
277	/// `/_matrix/client/v3/login/sso/redirect`, which the deployment's reverse
278	/// proxy must intercept to serve a custom list. Each entry links or
279	/// redirects to its configured provider at
280	/// `/_matrix/client/v3/login/sso/redirect/<client_id>`. The default false
281	/// lets clients generate their provider list or hide SSO options when none
282	/// are configured.
283	///
284	/// reloadable: yes
285	/// legacy: sso_custom_providers_page
286	#[serde(default)]
287	pub sso_custom_providers_page: bool,
288
289	/// Prefers OIDC-aware authentication under
290	/// [MSC3824](https://github.com/matrix-org/matrix-spec-proposals/pull/3824).
291	///
292	/// When clients find `oauth_aware_preferred` true and support that
293	/// authentication type, they should present it as the only login or
294	/// registration method.
295	///
296	/// reloadable: yes
297	/// legacy: oidc_aware_preferred sso_aware_preferred
298	#[serde(default, alias = "sso_aware_preferred")]
299	pub oidc_aware_preferred: bool,
300}
301
302/// Built-in OIDC server (next-generation login)
303///
304/// Provides a built-in OAuth 2.0 and OpenID Connect authorization server
305/// for clients using next-generation Matrix authentication (MSC2965). It
306/// runs only when `well_known.client` is set (it becomes the issuer URL)
307/// and at least one `[[global.identity_provider]]` exists or `native_auth`
308/// is true; otherwise these keys have no effect. Without `native_auth`,
309/// sign-in goes through the default identity provider; with it, a login
310/// page offers local accounts alongside the providers.
311///
312/// Minimal example (local accounts):
313///
314/// ```toml
315///     [global.well_known]
316///     client = "https://matrix.example.com"
317///
318///     [global.authentication.oidc]
319///     native_auth = true
320/// ```
321///
322/// Tips:
323/// - Whether the OIDC server runs is decided at startup: enabling it on a
324///   running server takes a restart.
325/// - Startup warns when `registration_access_token` is set (no Matrix client
326///   sends one), when `require_client_approval` is false, and when
327///   `native_auth` has neither password login nor a provider to offer.
328/// - The endpoint throttle needs both `rc_per_second` and `rc_burst_count`
329///   above zero; password checks on the built-in login page count against
330///   `[global.rate_limiting.login]` instead.
331#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
332// No Debug: secrets are reachable from this section.
333#[derive(Clone, Deserialize)]
334#[config_example_generator(
335	filename = "tuwunel-example.toml",
336	section = "global.authentication.oidc",
337	group = "true"
338)]
339pub struct Oidc {
340	/// Enables native registration and login on the built-in OIDC provider.
341	///
342	/// This authenticates next-generation Matrix clients against local
343	/// accounts without a third-party `identity_provider`; when false, as by
344	/// default, the provider only brokers authentication through a configured
345	/// upstream provider. When true, requests selecting no provider receive a
346	/// login or registration page and require `well_known.client`; the login
347	/// page offers local accounts and configured providers, with one SSO entry
348	/// under `authentication.login.single_sso` or
349	/// `authentication.login.sso_custom_providers_page`. An explicit `idp_id`
350	/// goes directly to its provider. Registration honors
351	/// `registration.enable`, the registration token, and root
352	/// `registration_terms` exactly as client registration does.
353	///
354	/// reloadable: yes
355	/// default: false
356	/// legacy: oidc_native_auth
357	#[serde(default)]
358	pub native_auth: bool,
359
360	/// Sets how long a browser stays signed in after a password sign-in on the
361	/// built-in login page, in seconds.
362	///
363	/// While it lasts, approving a new device from that browser, as in QR code
364	/// login, goes straight to the approval page without asking for the
365	/// password again. The lifetime counts from the sign-in and is not extended
366	/// by use; a lowered value applies to existing sign-ins at once, a value
367	/// above 7776000 (90 days) counts as 90 days, and 0 turns browser sign-in
368	/// off. Changing the password, deactivating the account or signing out of
369	/// all devices ends it early.
370	///
371	/// reloadable: yes
372	/// default: 2592000
373	#[serde(default = "default_browser_session_ttl")]
374	pub browser_session_ttl: u64,
375
376	/// Requires OIDC clients to request an
377	/// [MSC2967](https://github.com/matrix-org/matrix-spec-proposals/pull/2967)
378	/// device scope.
379	///
380	/// When false, clients omitting `urn:matrix:client:device:<id>` receive a
381	/// server-generated device ID echoed in the granted scope. When true,
382	/// authorization-code grants without a device scope are rejected,
383	/// following the proposal's expectation that clients own their device IDs.
384	///
385	/// reloadable: yes
386	/// default: false
387	/// legacy: oidc_require_device_scope
388	#[serde(default)]
389	pub require_device_scope: bool,
390
391	/// Requires [RFC 7636](https://www.rfc-editor.org/rfc/rfc7636) PKCE with
392	/// S256 on OIDC authorization-code grants.
393	///
394	/// When true, the authorize endpoint rejects requests without
395	/// `code_challenge`, as
396	/// [MSC2964](https://github.com/matrix-org/matrix-spec-proposals/pull/2964)
397	/// mandates for public clients. A supplied challenge must always use S256,
398	/// and `plain` is rejected regardless of this setting. Disable only
399	/// temporarily for a legacy client unable to send a challenge.
400	///
401	/// reloadable: yes
402	/// default: true
403	/// legacy: oidc_require_pkce
404	#[serde(default = "true_fn")]
405	pub require_pkce: bool,
406
407	/// Rejects OIDC authorization-code grants containing unrecognized scopes
408	/// instead of narrowing the grant.
409	///
410	/// When false, as by default, unknown scope tokens are dropped and the
411	/// narrowed `scope` is echoed to the client under [RFC
412	/// 6749](https://www.rfc-editor.org/rfc/rfc6749); when true, an unknown
413	/// scope is rejected. `openid` and both spellings of the
414	/// [MSC2967](https://github.com/matrix-org/matrix-spec-proposals/pull/2967)
415	/// device and API scopes are always recognized.
416	///
417	/// reloadable: yes
418	/// default: false
419	/// legacy: oidc_strict_scope
420	#[serde(default)]
421	pub strict_scope: bool,
422
423	/// Requires an initial access token for dynamic OIDC client registration
424	/// under [RFC 7591](https://www.rfc-editor.org/rfc/rfc7591).
425	///
426	/// When set, callers must supply it as an `Authorization: Bearer`
427	/// credential; clients that omit it cannot dynamically register for
428	/// next-generation login. Leave empty unless every OAuth client is
429	/// registered out of band.
430	///
431	/// display: sensitive
432	/// reloadable: yes
433	/// default:
434	/// legacy: oidc_registration_access_token
435	#[serde(default)]
436	pub registration_access_token: String,
437
438	/// Lists permitted hosts and private-use schemes for dynamically
439	/// registered OIDC redirect URIs.
440	///
441	/// When nonempty, every redirect URI must match or registration is
442	/// rejected: hosts match case-insensitively, while hostless private-use
443	/// URIs such as `io.element.android:/` match their scheme under [RFC
444	/// 8252](https://www.rfc-editor.org/rfc/rfc8252). For example,
445	/// `["element.io", "io.element.android"]` covers web and mobile clients.
446	///
447	/// The empty default imposes no registration restriction and vouches for
448	/// no client, so every sign-in remains subject to
449	/// `authentication.oidc.require_client_approval`. Listing an entry vouches
450	/// for any responding client: a scheme covers any device app claiming it
451	/// under [RFC 8252 section
452	/// 8.6](https://www.rfc-editor.org/rfc/rfc8252#section-8.6), and a host
453	/// covers every path.
454	///
455	/// reloadable: yes
456	/// default: []
457	/// legacy: oidc_registration_allowed_redirect_hosts
458	#[serde(default)]
459	pub registration_allowed_redirect_hosts: Vec<String>,
460
461	/// Asks users to approve unvetted OIDC clients before issuing
462	/// authorization codes.
463	///
464	/// Dynamic registration is open by default, so anyone can register a
465	/// controlled redirect target and send users an authorization link;
466	/// without confirmation, one click gives that client an account
467	/// authorization code. When true, as by default, unvetted sign-ins first
468	/// show an approve/deny page naming the client. A host or private-use
469	/// scheme listed in
470	/// `authentication.oidc.registration_allowed_redirect_hosts` vets its
471	/// client and restores prompt-free sign-in. When showing this prompt,
472	/// allow enough `authentication.login.token_ttl` for users to read it.
473	///
474	/// reloadable: yes
475	/// default: true
476	/// legacy: oidc_require_client_approval
477	#[serde(default = "true_fn")]
478	pub require_client_approval: bool,
479
480	/// Requires `client_uri` in dynamic registration under [RFC
481	/// 7591](https://www.rfc-editor.org/rfc/rfc7591) and
482	/// [MSC2966](https://github.com/matrix-org/matrix-spec-proposals/pull/2966).
483	///
484	/// When false, as by default, it is optional; any supplied URI still
485	/// requires HTTPS, a host, and no userinfo, and other request URLs must
486	/// share that host or a subdomain. When true, registrations lacking an
487	/// HTTPS `client_uri` fail with `invalid_client_metadata`, enforcing the
488	/// common-base model for every client.
489	///
490	/// reloadable: yes
491	/// default: false
492	/// legacy: oidc_registration_require_client_uri
493	#[serde(default)]
494	pub registration_require_client_uri: bool,
495
496	/// Sets the per-client-IP token-bucket refill rate for OIDC endpoints in
497	/// requests per second.
498	///
499	/// The throttle is shared across authorize, token, dynamic-registration,
500	/// and device-grant endpoints. The default 0 disables it and preserves
501	/// open access; raise this with `authentication.oidc.rc_burst_count` to
502	/// protect an exposed server. Because the key is client IP, rates that
503	/// limit brute force can also affect many users behind one NAT, so size
504	/// the burst accordingly.
505	///
506	/// reloadable: yes
507	/// default: 0
508	/// legacy: oidc_rc_per_second
509	#[serde(default)]
510	pub rc_per_second: u32,
511
512	/// Sets the token-bucket depth for the OIDC endpoint throttle.
513	///
514	/// This is the requests one client IP can make in a burst before
515	/// `authentication.oidc.rc_per_second` governs replenishment. It is
516	/// ignored when that refill rate is 0.
517	///
518	/// reloadable: yes
519	/// default: 0
520	/// legacy: oidc_rc_burst_count
521	#[serde(default)]
522	pub rc_burst_count: u32,
523}
524
525/// Refresh-token expiry and reuse
526///
527/// Applies to sessions that hold a refresh token: clients that request one
528/// at login or registration, and every client signed in through the built-in
529/// OIDC server. By default refresh tokens never expire, and a replay outside
530/// the 15-second grace window removes the device. Set `ttl` to expire idle
531/// sessions (`idle_only`) or sessions of a fixed age;
532/// `authentication.access_token_ttl` sets the access-token lifetime between
533/// refreshes.
534#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
535#[derive(Clone, Copy, Debug, Deserialize)]
536#[config_example_generator(
537	filename = "tuwunel-example.toml",
538	section = "global.authentication.refresh_token",
539	group = "true"
540)]
541pub struct RefreshToken {
542	/// Sets the refresh-token lifetime in seconds.
543	///
544	/// Tokens are rejected after this interval;
545	/// `authentication.refresh_token.idle_only` determines whether the
546	/// deadline slides with use or stays fixed at issuance. The default 0
547	/// disables refresh-token expiry entirely. A typical enabled value is
548	/// 259200, or three days.
549	///
550	/// reloadable: yes
551	/// default: 0
552	/// legacy: refresh_token_ttl
553	#[serde(default)]
554	pub ttl: u64,
555
556	/// Uses the refresh-token lifetime as an idle timeout instead of an
557	/// absolute session lifetime.
558	///
559	/// With a nonzero `authentication.refresh_token.ttl`, true, the default,
560	/// resets the deadline to now plus that lifetime after each successful
561	/// rotation; false retains an existing deadline rather than extending it. A
562	/// successful grace replay retains its current successor and does not
563	/// reset that successor's deadline. A zero TTL issues replacement tokens
564	/// without expiry.
565	///
566	/// reloadable: yes
567	/// default: true
568	/// legacy: refresh_token_idle_only
569	#[serde(default = "true_fn")]
570	pub idle_only: bool,
571
572	/// Removes the device on refresh-token expiry instead of soft-logging out.
573	///
574	/// When false, as by default, expiry returns `M_UNKNOWN_TOKEN` with
575	/// `soft_logout: true`, allowing the client to retain E2EE keys and local
576	/// state and reauthenticate on the same device. When true, expiry
577	/// invalidates the access token, deletes the device record, and signals
578	/// `soft_logout: false`; the next session uses a new device and cannot
579	/// recover E2EE history from local state alone, trading usability for the
580	/// [CWE-613](https://cwe.mitre.org/data/definitions/613.html) guarantee.
581	/// Tokens issued with zero TTL do not expire, and changing the current TTL
582	/// does not remove an already stored expiry.
583	///
584	/// reloadable: yes
585	/// default: false
586	/// legacy: refresh_token_hard_logout
587	#[serde(default)]
588	pub hard_logout: bool,
589
590	/// Sets the grace window in seconds for a benign refresh-token double
591	/// submission.
592	///
593	/// After rotation, the spent token is retained for one generation; within
594	/// a nonzero window, a replay can issue a fresh access token while
595	/// retaining its current, resolvable, unexpired successor. An expired
596	/// successor triggers the configured expiry logout, while an unresolvable
597	/// successor is refused without changes.
598	///
599	/// A token classified as spent outside grace on arrival is rejected, with
600	/// device revocation only when `authentication.refresh_token.reuse_revoke`
601	/// is enabled; zero disables grace. A request current on arrival but spent
602	/// while waiting for the device lock can instead be refused without
603	/// revocation, including at zero grace.
604	///
605	/// reloadable: yes
606	/// default: 15
607	/// legacy: refresh_token_reuse_grace
608	#[serde(default = "default_reuse_grace")]
609	pub reuse_grace: u64,
610
611	/// Revokes the device when refresh-token reuse is detected.
612	///
613	/// When true, as by default, reuse detected outside
614	/// `authentication.refresh_token.reuse_grace` on arrival removes the
615	/// device under the
616	/// [RFC 6819](https://www.rfc-editor.org/rfc/rfc6819) compromised-session
617	/// model. When false, the replayed request is rejected but the device
618	/// remains intact, a less restrictive behavior operators using another
619	/// OAuth client may prefer.
620	///
621	/// reloadable: yes
622	/// default: true
623	/// legacy: refresh_token_reuse_revoke
624	#[serde(default = "true_fn")]
625	pub reuse_revoke: bool,
626}
627
628impl Default for Authentication {
629	fn default() -> Self {
630		Self {
631			mas_secret: None,
632			openid_token_ttl: default_openid_token_ttl(),
633			access_token_ttl: default_access_token_ttl(),
634			emergency_password: None,
635			argon2: Argon2::default(),
636			login: Login::default(),
637			oidc: Oidc::default(),
638			refresh_token: RefreshToken::default(),
639		}
640	}
641}
642
643impl Default for Argon2 {
644	fn default() -> Self {
645		Self {
646			m_cost: default_m_cost(),
647			t_cost: default_t_cost(),
648			p_cost: default_p_cost(),
649		}
650	}
651}
652
653impl Default for Login {
654	fn default() -> Self {
655		Self {
656			via_existing_session: true_fn(),
657			via_token: true_fn(),
658			with_password: true_fn(),
659			token_ttl: default_token_ttl(),
660			single_sso: Default::default(),
661			sso_custom_providers_page: Default::default(),
662			oidc_aware_preferred: Default::default(),
663		}
664	}
665}
666
667impl Default for Oidc {
668	fn default() -> Self {
669		Self {
670			native_auth: Default::default(),
671			browser_session_ttl: default_browser_session_ttl(),
672			require_device_scope: Default::default(),
673			require_pkce: true_fn(),
674			strict_scope: Default::default(),
675			registration_access_token: Default::default(),
676			registration_allowed_redirect_hosts: Default::default(),
677			require_client_approval: true_fn(),
678			registration_require_client_uri: Default::default(),
679			rc_per_second: Default::default(),
680			rc_burst_count: Default::default(),
681		}
682	}
683}
684
685impl Default for RefreshToken {
686	fn default() -> Self {
687		Self {
688			ttl: Default::default(),
689			idle_only: true_fn(),
690			hard_logout: Default::default(),
691			reuse_grace: default_reuse_grace(),
692			reuse_revoke: true_fn(),
693		}
694	}
695}
696
697fn default_openid_token_ttl() -> u64 { 60 * 60 }
698
699fn default_access_token_ttl() -> u64 { 604_800 }
700
701fn default_browser_session_ttl() -> u64 { 60 * 60 * 24 * 30 }
702
703fn default_m_cost() -> u32 { 19 * 1024 }
704
705fn default_t_cost() -> u32 { 2 }
706
707fn default_p_cost() -> u32 { 1 }
708
709fn default_token_ttl() -> u64 { 2 * 60 * 1000 }
710
711fn default_reuse_grace() -> u64 { 15 }