tablo_core/auth/config.rs
1//! [`Auth`]: the panel's authentication configuration, from the authenticator to the pages and
2//! mail it adds.
3
4use std::{marker::PhantomData, sync::Arc};
5
6#[cfg(feature = "two-factor")]
7use super::TwoFactor;
8use super::{
9 AdminUser, AuthMail, Authenticator, DynAuthenticator, EmailVerification, LoginThrottle,
10 PanelUser, PasswordAuth, PasswordReset, ProfileEditor, Registrar, TenantEditor,
11 TenantRegistration,
12 external::{DynExternal, ExternalAuth, ExternalUsers},
13 profile::DynProfileEditor,
14 registration::DynRegistrar,
15 tenant_profile::DynTenantEditor,
16};
17
18/// The panel's authentication configuration (ADR-0013).
19///
20/// The default is [`Auth::password`]; [`Auth::custom`] installs an app-owned
21/// [`Authenticator`]; [`Auth::external`] hands sign-in to the host app; [`Auth::disabled`] is the
22/// explicit fail-open opt-out.
23/// Sign-in attempts are throttled per login and address by default; see [`Auth::throttle`].
24/// [`Auth::account_throttle`] adds an opt-in count per login across addresses.
25/// [`Auth::registration`] adds a sign-up page, [`Auth::profile`] a profile page, and
26/// [`Auth::password_reset`] a forgot-password page that mails reset links through
27/// [`Auth::mail`], [`Auth::tenant_registration`] a page creating a tenant, and
28/// [`Auth::tenant_profile`] a page editing one.
29///
30/// `U` is the user type the authenticator loads. Every seam that reads or writes a user, from the
31/// registrar to the tenant editor, names the same type, so a seam over another user type does not
32/// compile.
33pub struct Auth<U = AdminUser> {
34 pub(super) config: AuthConfig,
35 /// Whether every throttle counts in the database, set by [`Auth::throttles_in_database`].
36 throttles_in_database: bool,
37 user: PhantomData<fn() -> U>,
38}
39
40impl Auth {
41 /// The shipped Argon2id + [`AdminUser`] authenticator.
42 #[must_use]
43 pub fn password() -> Self {
44 Self::custom(PasswordAuth::new())
45 }
46
47 /// Explicit fail-open opt-out for public demos (ADR-0013): no gate, no
48 /// login routes, sessions unused.
49 ///
50 /// It is no way to put the panel behind an app's own sign-in: a layer over the prefix leaves
51 /// Topcoat's runtime path open, where the panel's search and other endpoints answer anyone.
52 /// [`Auth::external`] gates both.
53 #[must_use]
54 pub fn disabled() -> Self {
55 Self::new(AuthConfig::new(None, LoginThrottle::off))
56 }
57}
58
59impl<U: PanelUser> Auth<U> {
60 /// An app-owned authenticator over its own user table.
61 #[must_use]
62 pub fn custom<A: Authenticator<User = U>>(authenticator: A) -> Self {
63 let authenticator: Box<dyn DynAuthenticator> = Box::new(authenticator);
64 Self::new(AuthConfig::new(Some(authenticator), LoginThrottle::default))
65 }
66
67 /// A panel whose users sign in through the host app: no password form, and no credential of
68 /// Tablo's. See [`ExternalAuth`].
69 ///
70 /// Mounting refuses what needs Tablo to own the credentials:
71 /// [`registration`](Self::registration), [`password_reset`](Self::password_reset),
72 /// [`email_verification`](Self::email_verification), [`two_factor`](Self::two_factor),
73 /// [`impersonation`](Self::impersonation) and [`oidc`](Self::oidc).
74 #[must_use]
75 pub fn external<E: ExternalAuth<User = U>>(external: E) -> Self {
76 let external = Arc::new(external);
77 let mut auth = Self::custom(ExternalUsers(Arc::clone(&external)));
78 auth.config.external = Some(external);
79 auth
80 }
81
82 fn new(config: AuthConfig) -> Self {
83 Self {
84 config,
85 throttles_in_database: false,
86 user: PhantomData,
87 }
88 }
89
90 /// How many sign-in attempts one login may make from one client address
91 /// in a window; defaults to five a minute. [`LoginThrottle::off`] counts nothing, for a proxy
92 /// that limits sign-ins itself.
93 #[must_use]
94 pub fn throttle(mut self, throttle: LoginThrottle) -> Self {
95 self.config.throttle = throttle;
96 self
97 }
98
99 /// How many sign-in attempts one login may make from all addresses together in a window;
100 /// off by default. It stops a guesser who rotates addresses, at the cost of letting anyone
101 /// who knows a login refuse its owner until the window ends, again each window; a successful
102 /// sign-in clears it. Turn it on where a guessed password costs more than a locked-out
103 /// owner, with a limit high enough that only a distributed guesser reaches it, such as
104 /// `LoginThrottle::new(50, Duration::from_hours(1))`.
105 #[must_use]
106 pub fn account_throttle(mut self, throttle: LoginThrottle) -> Self {
107 self.config.account_throttle = throttle;
108 self
109 }
110
111 /// Keeps the counts of every throttle the panel declares in the database, as
112 /// [`LoginThrottle::in_database`] keeps one's: the defaults and the ones set before or after
113 /// this call, on sign-in, sign-up, the profile, password reset, email verification and
114 /// two-factor sign-in alike. A deployment of several replicas turns it on, so that each limit
115 /// holds across them rather than once per process.
116 ///
117 /// ```rust
118 /// use std::time::Duration;
119 ///
120 /// use tablo_core::{Auth, LoginThrottle};
121 ///
122 /// let auth = Auth::password()
123 /// .throttles_in_database()
124 /// .account_throttle(LoginThrottle::new(50, Duration::from_hours(1)));
125 /// # let _ = auth;
126 /// ```
127 #[must_use]
128 pub fn throttles_in_database(mut self) -> Self {
129 self.throttles_in_database = true;
130 self
131 }
132
133 /// Lets visitors create their own account at `{prefix}/register`, through `registrar`; the
134 /// login page links to it.
135 ///
136 /// ```rust
137 /// use tablo_core::{Auth, PasswordSignUp};
138 ///
139 /// let auth = Auth::password().registration(PasswordSignUp::pending());
140 /// # let _ = auth;
141 /// ```
142 ///
143 /// [`PasswordSignUp`](crate::PasswordSignUp) registers an [`AdminUser`](super::AdminUser) from
144 /// a [`SignUp`](super::SignUp), inactive until an administrator approves it or, when built
145 /// with `open`, active and signed in at once. A custom [`Registrar`] decides what a new
146 /// account may do; one whose user may not access the panel lands on the login page.
147 ///
148 /// - The form is any `FormInput`, or the shipped `SignUp`. `#[form(password)]` renders a masked
149 /// control, with a button that shows what was typed, that a refused form renders empty, and
150 /// reads the password as typed, outer spaces included, as the login compares it.
151 /// `#[form(email)]` refuses a malformed address before `validate` runs. A missing field and a
152 /// malformed value answer 422 with the error under the field, as `validate`'s refusals do;
153 /// nothing is written.
154 /// - `new_password_errors` refuses a password under eight characters and a confirmation that
155 /// differs, under the `password` and `password_confirmation` keys.
156 /// - After the commit, an account that may open the panel is signed in, its session rotated as
157 /// a login rotates it, and lands on `next` or the panel's home page. One that may not, such
158 /// as an account awaiting approval, lands on the login page with a notification instead. A
159 /// signed-in user who opens the sign-up page lands on the panel's home page.
160 /// - The registrar's `User` is `U`. Mounting refuses a registration on `Auth::disabled()`, a
161 /// form field named `csrf_token` or `next`, a file field and a relationship choice, whose
162 /// options would list records to a visitor nobody signed in.
163 /// - Throttling. Each client address may submit five sign-ups a minute, counted whether or not
164 /// they create an account; `Auth::sign_up_throttle` changes the limit. Past it the page
165 /// answers 429.
166 ///
167 /// The sign-up page tells a visitor whether an email is taken, which the login page never does:
168 /// an app that must keep its accounts private verifies the address by email before saying so,
169 /// which Tablo does not ship.
170 #[must_use]
171 pub fn registration(mut self, registrar: impl Registrar<User = U>) -> Self {
172 self.config.registrar = Some(Box::new(registrar));
173 self
174 }
175
176 /// How many sign-ups one client address may submit in a window; defaults to five a minute.
177 /// Every sign-up POST that passes the CSRF check and parses counts, whether or not it creates
178 /// an account.
179 #[must_use]
180 pub fn sign_up_throttle(mut self, throttle: LoginThrottle) -> Self {
181 self.config.sign_up_throttle = throttle;
182 self
183 }
184
185 /// Lets the signed-in user edit their own account at `{prefix}/profile`, through `editor`;
186 /// the user menu links to it.
187 ///
188 /// ```rust
189 /// use tablo_core::{Auth, PasswordAuth};
190 ///
191 /// let auth = Auth::password().profile(PasswordAuth::new());
192 /// # let _ = auth;
193 /// ```
194 ///
195 /// [`PasswordAuth`] edits a [`PasswordAccount`](super::PasswordAccount)'s name, email and
196 /// password through a [`Profile`](super::Profile), asking for the current password before the
197 /// email or the password changes.
198 ///
199 /// - The form is any `FormInput`, rendered in the panel's shell. The page shows what the
200 /// input's `write` writes, so `Profile` never shows a password. A disabled control keeps what
201 /// `fill` wrote, whatever the POST carries. A refused save renders the form again with each
202 /// error under its field; nothing is written.
203 /// - `save` answers `ProfileUpdate::Details`, which keeps every session, or
204 /// `ProfileUpdate::Credentials` for a change to what the user signs in with. The user's
205 /// sessions then end on every panel whose authenticator loads the same user type, in the
206 /// transaction that saves, and the browser that saved gets a new session under the tenant it
207 /// acted for. `PasswordAuth` answers `Credentials` for a new email or password.
208 /// - An email another account holds is reported only once the current password verifies, so a
209 /// stolen session cannot probe which addresses have accounts.
210 /// - After the commit the page reloads with a notification.
211 /// - The editor's `User` is `U`. Mounting refuses a profile on `Auth::disabled()`, a form field
212 /// named `csrf_token`, a file field and a relationship choice, whose options no route serves
213 /// the page.
214 /// - Throttling. Each user may submit five saves a minute, from any address, counted whether or
215 /// not they save; `Auth::profile_throttle` changes the limit. Past it the page answers 429,
216 /// which keeps a stolen session from guessing the current password. A user past the limit can
217 /// still sign in.
218 #[must_use]
219 pub fn profile(mut self, editor: impl ProfileEditor<User = U>) -> Self {
220 self.config.profile_editor = Some(Box::new(editor));
221 self
222 }
223
224 /// How many profile saves one user may submit in a window, from any address; defaults to five
225 /// a minute. Every profile POST that passes the CSRF check and parses counts, whether or not
226 /// it saves.
227 #[must_use]
228 pub fn profile_throttle(mut self, throttle: LoginThrottle) -> Self {
229 self.config.profile_throttle = throttle;
230 self
231 }
232
233 /// Lets a visitor who forgot their password ask for a reset link at
234 /// `{prefix}/forgot-password`, mailed through [`Auth::mail`], and choose a new password at
235 /// `{prefix}/reset-password`; the login page links to it.
236 ///
237 /// - The request page answers the same whether an account uses the address or not: it redirects
238 /// to the login page with a notification, and writes and mails the link after answering, so
239 /// the database and the mail server add no time when an account exists. An account that may
240 /// not enter the panel gets no link, and a failed send is logged, not shown.
241 /// - The link goes to the stored address, never the typed one. A lookup that matches loosely,
242 /// such as a collation that folds accents, would otherwise mail one account's link to another
243 /// address.
244 /// - A link works once, for one hour, on the panel that mailed it, and only while the account
245 /// may still enter the panel. A new request replaces the account's earlier link, and a
246 /// password change on the profile page ends it, as it ends every link the account holds. The
247 /// token is stored only as a hash, and the reset page sends no referrer and may not be
248 /// cached.
249 /// - A reset checks the new password with `new_password_errors`, then sets it, ends the
250 /// account's sessions and reset links on every panel whose authenticator loads the same user
251 /// type, and redirects to the login page. All of this commits in one transaction.
252 /// - Throttling. Each address may request three links in fifteen minutes, from any client,
253 /// counted whether or not an account uses it; `PasswordReset::throttle` changes the limit.
254 /// Past it the page answers 429. A limit per client belongs at the proxy.
255 /// - The resetter's `User` is `U`. Mounting refuses a reset on `Auth::disabled()`, a reset
256 /// without `Auth::mail`, a base URL that is not an absolute `http` or `https` URL or that
257 /// carries a query or fragment, and a router without a `Mailer` unless `AuthMail::delivery`
258 /// takes the mail.
259 #[must_use]
260 pub fn password_reset(mut self, reset: PasswordReset<U>) -> Self {
261 self.config.reset = Some(reset.erase());
262 self
263 }
264
265 /// Makes each signed-in user prove they read the address [`PanelUser::email`] answers before
266 /// they reach anything but `{prefix}/verify-email`, which mails them a link through
267 /// [`Auth::mail`]. A sign-up mails the link at once, after the response.
268 ///
269 /// - Until the user verifies, a page redirects to `{prefix}/verify-email` and any other request
270 /// answers 403. The page offers to mail a link, and to sign out. A user whose
271 /// `PanelUser::email` is `None` has no address to prove and is not held.
272 /// - Accounts that predate verification are unverified: turning it on sends each of them,
273 /// seeded admins included, to `{prefix}/verify-email` at their next request. Backfill
274 /// `email_verified_at` (from `created_at`, say) for the addresses you already trust.
275 /// - A link works once, for one day, on the panel that mailed it, and only while the account
276 /// may enter the panel and still stores the address it was mailed to. It verifies on `GET` in
277 /// any browser, signed in or not, then lands on the panel or on the login page. A mail
278 /// scanner that opens the link verifies the address too: it fetched the link from the mailbox
279 /// the link proves.
280 /// - A new email waits for its own link. A profile editor calls `auth::request_email_change`
281 /// from `save` in place of writing the address: on a panel with email verification it records
282 /// the change and answers `EmailChange::Pending`, and once the save commits the panel mails
283 /// the new address a link that stores it and the old address a link that keeps it. Elsewhere
284 /// it answers `EmailChange::Immediate` and the editor stores the address itself.
285 /// `PasswordAuth` does this. The link proves only that whoever asked reads the new mailbox,
286 /// so ask for the current password before calling it, as `PasswordAuth` does: a stolen
287 /// session could name its thief's mailbox.
288 /// - Either link opens a page whose button does the work, so a mail scanner that fetches it
289 /// changes nothing.
290 /// - The new address's link stores it, verified, once, for one day. It is a credential change:
291 /// the account's sessions and sign-in links end on every panel signing in its user type, and
292 /// the browser that confirmed keeps a new session when it was signed in as the account.
293 /// - The old address's link works for a week, before or after the change goes through: it keeps
294 /// the old address, restoring it if the change went through, and ends every session, sign-in
295 /// link and pending change the account holds, the cancelling browser's included: whoever
296 /// asked for the change may hold one.
297 /// - Throttling. Each account may ask for three links in fifteen minutes;
298 /// `EmailVerification::throttle` changes the limit. Past it the page answers 429.
299 /// - The verifier's `User` is `U`. Mounting refuses a verification on `Auth::disabled()`, and
300 /// one without `Auth::mail`.
301 ///
302 /// [`PanelUser::email`]: super::PanelUser::email
303 #[must_use]
304 pub fn email_verification(mut self, verification: EmailVerification<U>) -> Self {
305 self.config.verification = Some(verification.erase());
306 self
307 }
308
309 /// Lets the signed-in user create a tenant to act for at `{prefix}/register-tenant`, through
310 /// `registration`'s [`TenantRegistrar`](crate::TenantRegistrar); the tenant menu links to
311 /// it from one membership on. [`TenantRegistration::required`] sends a user who acts for no
312 /// tenant there first.
313 ///
314 /// The registrar's `Input` is the page's form; `validate` and `register` run in one
315 /// transaction, and `register` writes the tenant and the user's membership of it, answering
316 /// that [`Membership`](crate::Membership). The session then acts for the new tenant, and the
317 /// next request's [`find_by_id`](crate::Authenticator::find_by_id) must list it.
318 ///
319 /// The registrar's [`User`](crate::TenantRegistrar::User) is `U`. Mounting refuses a
320 /// registration on [`Auth::disabled`], a form field named `csrf_token`, a file field and a
321 /// relationship choice.
322 #[must_use]
323 pub fn tenant_registration(mut self, registration: TenantRegistration<U>) -> Self {
324 self.config.tenant_registration = Some(registration.erase());
325 self
326 }
327
328 /// Lets the signed-in user edit the tenant they act for at `{prefix}/tenant/profile`, through
329 /// `editor`; the tenant menu links to it for a user [`TenantEditor::may_edit`] admits, and the
330 /// page answers 403 to anyone else. `fill` loads the form from the tenant, and `validate` and
331 /// `save` run in one transaction. The form names the tenant it was filled from, so one posted
332 /// after another tab switched tenants saves nothing.
333 ///
334 /// The editor's [`User`](TenantEditor::User) is `U`. Mounting refuses a settings page on
335 /// [`Auth::disabled`], a form field named `csrf_token` or `editing_tenant`, a file field and a
336 /// relationship choice.
337 #[must_use]
338 pub fn tenant_profile(mut self, editor: impl TenantEditor<User = U>) -> Self {
339 self.config.tenant_editor = Some(Box::new(editor));
340 self
341 }
342
343 /// Lets each signed-in user add an authenticator app at `{prefix}/two-factor`; the user menu
344 /// links to it. An account with one signs in with a code from it, or a recovery code, at
345 /// `{prefix}/two-factor-challenge` after its password.
346 ///
347 /// - Setting up happens at `{prefix}/two-factor`, which the user menu links to. It asks for the
348 /// current password first, through `Authenticator::confirm_password`, so a stolen session
349 /// cannot add a factor its thief holds. That method verifies with the user's
350 /// `PanelUser::email` as the login; override it when users sign in with something else. The
351 /// page then shows a QR code and the key, and turns two-factor sign-in on once a code from
352 /// the app matches. It then shows eight recovery codes, once: the panel stores only their
353 /// hashes, keyed like the secrets.
354 /// - Panels that load the same user type share an account's factor: set up on one, it is asked
355 /// on each that installs two-factor sign-in. Panels of another user type share nothing.
356 /// - Signing in, a correct password leads to `{prefix}/two-factor-challenge` instead of a
357 /// session. The challenge lasts five minutes in its own cookie and takes a code from the app
358 /// or a recovery code. Each code works once: an app code does not sign in twice, and a
359 /// recovery code is used up.
360 /// - Wrong codes. Every fifth wrong code in a row ends the challenge, so the next try takes the
361 /// password again. Past the fifth, each code of the app or the mail waits for the one before
362 /// it: 30 seconds, doubling up to an hour, across challenges, until a right code; a recovery
363 /// code never waits. Each fifth mails the account, through `Auth::mail`, that its password
364 /// signed in and codes failed. Someone holding the password can so keep the app's codes
365 /// waiting and make the owner spend recovery codes; the mail tells the owner, and a new
366 /// password ends it.
367 /// - Turning it on or off is a credential change: the account's other sessions and links end.
368 /// Turning it off, and showing new recovery codes, take a code.
369 /// - Codes by email. `TwoFactor::new().email_codes()` lets a user with an address choose codes
370 /// mailed to it in place of an app, through `Auth::mail`. Each sign-in mails a six-digit code
371 /// that works once, for ten minutes; the challenge page mails a new one on request, in place
372 /// of the last. Each account may have three mailed in fifteen minutes;
373 /// `TwoFactor::mail_throttle` changes the limit. An account holds one factor at a time: it
374 /// turns one off before setting up the other. A panel that drops `email_codes()` mails no
375 /// more codes: an account set up for them signs in with a recovery code. A mail server that
376 /// fails leaves the challenge up, with its button to send another code.
377 /// - Throttling. Each account may try five codes or passwords a minute, at sign-in and on the
378 /// settings page together; `TwoFactor::throttle` changes the limit. Past it the page answers
379 /// 429. The count lives in each process, so behind several the limit holds per process,
380 /// unless the throttle counts `in_database`. Someone who knows the password can use up the
381 /// owner's attempts, and each new sign-in replaces the last challenge.
382 /// - The cookie `Key` seals the secrets. Rotating it makes every app code fail until its owner
383 /// signs in with a recovery code and sets the app up again; a leaked key opens every secret.
384 /// - Requiring it. `TwoFactor::new().required()` sends a signed-in user without a second factor
385 /// to `{prefix}/two-factor` before anything else, as an unverified address does: a page
386 /// redirects there and any other request answers 403. `TwoFactor::required_for` does so for
387 /// the users its rule names.
388 /// - Mounting refuses two-factor sign-in on `Auth::disabled()`, a router without a cookie
389 /// `Key`, and codes by email without `Auth::mail`.
390 #[cfg(feature = "two-factor")]
391 #[must_use]
392 pub fn two_factor(mut self, two_factor: TwoFactor) -> Self {
393 self.config.two_factor = Some(two_factor);
394 self
395 }
396
397 /// Sends the panel's auth mail, such as reset links, from `mail`'s sender, with links that
398 /// start with its base URL. Mounting refuses a base URL that is not absolute, and a router
399 /// without a [`Mailer`](topcoat::mail::Mailer) unless [`AuthMail::delivery`] takes the mail.
400 #[must_use]
401 pub fn mail(mut self, mail: AuthMail) -> Self {
402 self.config.mail = Some(mail);
403 self
404 }
405
406 /// Whether the explicit opt-out is set.
407 #[must_use]
408 pub fn is_disabled(&self) -> bool {
409 self.config.is_disabled()
410 }
411
412 /// The declaration, its user type checked.
413 pub(crate) fn into_config(mut self) -> AuthConfig {
414 if self.throttles_in_database {
415 self.config.count_throttles_in_database();
416 }
417 self.config
418 }
419}
420
421impl Default for Auth {
422 fn default() -> Self {
423 Self::password()
424 }
425}
426
427/// What an [`Auth`] declares, with the user type erased once the builder has checked it.
428pub(crate) struct AuthConfig {
429 authenticator: Option<Box<dyn DynAuthenticator>>,
430 external: Option<Arc<dyn DynExternal>>,
431 throttle: LoginThrottle,
432 account_throttle: LoginThrottle,
433 pub(super) registrar: Option<Box<dyn DynRegistrar>>,
434 sign_up_throttle: LoginThrottle,
435 pub(super) profile_editor: Option<Box<dyn DynProfileEditor>>,
436 profile_throttle: LoginThrottle,
437 pub(super) reset: Option<PasswordReset<()>>,
438 pub(super) mail: Option<AuthMail>,
439 pub(super) verification: Option<EmailVerification<()>>,
440 pub(super) tenant_registration: Option<TenantRegistration<()>>,
441 pub(super) tenant_editor: Option<Box<dyn DynTenantEditor>>,
442 #[cfg(feature = "two-factor")]
443 pub(super) two_factor: Option<TwoFactor>,
444 pub(super) impersonation: Option<super::impersonation::ImpersonationConfig>,
445 pub(super) oidc: Option<super::oidc::Oidc<()>>,
446 pub(super) sessions: super::session::Sessions,
447}
448
449impl AuthConfig {
450 /// `authenticator` with no feature on, its default throttles from `throttle`.
451 fn new(
452 authenticator: Option<Box<dyn DynAuthenticator>>,
453 throttle: fn() -> LoginThrottle,
454 ) -> Self {
455 Self {
456 authenticator,
457 external: None,
458 throttle: throttle(),
459 account_throttle: LoginThrottle::off(),
460 registrar: None,
461 sign_up_throttle: throttle(),
462 profile_editor: None,
463 profile_throttle: throttle(),
464 reset: None,
465 mail: None,
466 verification: None,
467 tenant_registration: None,
468 tenant_editor: None,
469 #[cfg(feature = "two-factor")]
470 two_factor: None,
471 impersonation: None,
472 oidc: None,
473 sessions: super::session::Sessions::new(),
474 }
475 }
476
477 /// Whether the explicit opt-out is set.
478 pub(crate) fn is_disabled(&self) -> bool {
479 self.authenticator.is_none()
480 }
481
482 /// The authenticator, or `None` when auth is disabled.
483 pub(crate) fn authenticator(&self) -> Option<&dyn DynAuthenticator> {
484 self.authenticator.as_deref()
485 }
486
487 /// The host app's sign-in, when [`Auth::external`] installs it.
488 pub(crate) fn external(&self) -> Option<&dyn DynExternal> {
489 self.external.as_deref()
490 }
491
492 /// The sign-in throttle.
493 pub(crate) fn login_throttle(&self) -> &LoginThrottle {
494 &self.throttle
495 }
496
497 /// The sign-in throttle counted per login across addresses.
498 pub(crate) fn account_throttle_of(&self) -> &LoginThrottle {
499 &self.account_throttle
500 }
501
502 /// The registrar, or `None` without a sign-up page.
503 pub(crate) fn registrar(&self) -> Option<&dyn DynRegistrar> {
504 self.authenticator.as_ref().and(self.registrar.as_deref())
505 }
506
507 /// The sign-up throttle, counted per client address.
508 pub(crate) fn throttle_sign_ups(&self) -> &LoginThrottle {
509 &self.sign_up_throttle
510 }
511
512 /// The profile editor, or `None` without a profile page.
513 pub(crate) fn profile_editor(&self) -> Option<&dyn DynProfileEditor> {
514 self.authenticator
515 .as_ref()
516 .and(self.profile_editor.as_deref())
517 }
518
519 /// The profile throttle, counted per user.
520 pub(crate) fn throttle_profile(&self) -> &LoginThrottle {
521 &self.profile_throttle
522 }
523
524 /// The password reset, or `None` without a forgot-password page.
525 pub(crate) fn reset(&self) -> Option<&PasswordReset<()>> {
526 self.authenticator.as_ref().and(self.reset.as_ref())
527 }
528
529 /// The email verification, or `None` when the panel asks for none.
530 pub(crate) fn verification(&self) -> Option<&EmailVerification<()>> {
531 self.authenticator.as_ref().and(self.verification.as_ref())
532 }
533
534 /// The tenant registration, or `None` without a tenant registration page.
535 pub(crate) fn tenant_registration_page(&self) -> Option<&TenantRegistration<()>> {
536 self.authenticator
537 .as_ref()
538 .and(self.tenant_registration.as_ref())
539 }
540
541 /// The tenant editor, or `None` without a tenant settings page.
542 pub(crate) fn tenant_editor(&self) -> Option<&dyn DynTenantEditor> {
543 self.authenticator
544 .as_ref()
545 .and(self.tenant_editor.as_deref())
546 }
547
548 /// The provider sign-in, or `None` when the panel offers none.
549 pub(crate) fn oidc(&self) -> Option<&super::oidc::Oidc<()>> {
550 self.authenticator.as_ref().and(self.oidc.as_ref())
551 }
552
553 /// The auth mail, or `None` when the panel mails nothing.
554 pub(crate) fn auth_mail(&self) -> Option<&AuthMail> {
555 self.authenticator.as_ref().and(self.mail.as_ref())
556 }
557
558 /// The features that send mail, by name, for the mount's checks.
559 pub(super) fn mailing(&self) -> Vec<&'static str> {
560 [
561 self.reset.is_some().then_some("password_reset"),
562 self.verification.is_some().then_some("email_verification"),
563 self.two_factor_mails().then_some("two_factor"),
564 ]
565 .into_iter()
566 .flatten()
567 .collect()
568 }
569
570 /// Whether the panel issues [`AuthToken`](super::AuthToken)s, so the model must be registered:
571 /// it mails links, or challenges a second factor.
572 pub(crate) fn issues_tokens(&self) -> bool {
573 self.authenticator.is_some() && (!self.mailing().is_empty() || self.two_factor_declared())
574 }
575}
576
577mod debug;
578mod throttles;
579mod two_factor;