A way back into an account
Offer a second passkey first. Then choose:
| Method | Routes below /auth | The application does | Strength |
|---|---|---|---|
| Recovery key | recovery/key, recovery/key/start, recovery/key/finish | Nothing, if users have an identifier | Strong |
| Approval by an owner | recovery/owner, then the link | Hooks::may_recover | Strong, if people check each other |
recovery/email, then the link | Config::with_email_recovery, verified_address, send | Weak: 24 hours of waiting, notices, 72 hours of hold |
use auth_chad::axum::{Hooks, Mail};
use auth_chad::sqlite::SqliteStore;
use auth_chad::{Authenticated, UserId};
struct App;
impl Hooks<SqliteStore> for App {
async fn verified_address(&self, _store: &SqliteStore, address: &str) -> Option<UserId> {
None // look up an address that you verified, never one that a person only typed
}
async fn may_recover(&self, who: &Authenticated, user: UserId) -> bool {
false // is `who` an owner of an organization of `user`?
}
async fn send(&self, mail: Mail<'_>) -> bool {
match mail {
// A secret. The link opens a page with a button: mail scanners open links.
Mail::Link { to, token } => false,
// "Someone asked for a new passkey. It works at … . Cancel it here."
Mail::Notice { to, ready_at } => false,
}
}
}
In the browser (/auth/auth-chad.js):
const text = await newRecoveryKey(); // show it once; needs a recent passkey
await recoverWithKey({ identifier: "jane", displayName: "Jane", key: text });
await recoverByEmail("jane@example.com"); // the same answer if there is no account
await recoverWithLink({ token, userName: "jane", displayName: "Jane" });
const { ready_at, hold_until } = await recovery(); // show it: cancelRecovery(), undoRecovery()
- Run the worker (
auth_chad::axum::work, see load-balancer): it sends a mail that failed again. - Show
ready_aton every page of a logged-in user. A cancel there stops someone who has the mailbox. - Use
Hooks::commit_recoveryto add a notice for every other address of the user.
Never use email recovery with e2ee: it cannot restore a key.