Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Flows

Summary: how data moves through auth-chad: the check on every request, the decide-then-commit loop, and the main journeys (signup, login, device login, recovery, connected apps).
Key terms: request check, decide, commit, ceremony, DPoP, fresh login, device code, envelope, hold, outbox, worker.
Related: Data · Concepts · spec 02

Every request passes the same check. The auth-chad layer reads the cookie or the signed token, looks up the session in the database, and either creates an Authenticated value or rejects the request; then your handler runs. A request that changes an account calls a flow, which decides the change. The change and its audit event are stored in one transaction. Work that must follow the change, such as a mail, waits in the outbox until the worker runs it.

The check on every request

The picture as text
sequenceDiagram
    participant C as Client
    participant L as auth-chad layer
    participant DB as Users' database
    participant H as Your handler
    C->>L: request + cookie, or token + DPoP proof
    L->>DB: read the session or token, mark the proof as used
    alt valid
        L->>H: Authenticated (who, tenant, level, key, last passkey use)
        H-->>C: your response
    else invalid
        L-->>C: 401 or 403 with {"error": code}
    end
  • The check runs on every request, and its result is never cached. A logout takes effect on the next request, in every process.
  • If the database cannot answer, the request fails with 503.

Decide, then commit

The picture as text
flowchart LR
    R[Request] --> F["Flow<br/>(reads, decides)"]
    F --> D["Decision<br/>out + writes"]
    D --> A["+ your writes<br/>(hooks)"]
    A --> T[["One transaction<br/>all or nothing"]]
    T -->|ok| O[Use out: respond to the client]
    T -->|a condition failed| X[conflict: nothing changed]

A login in code: the passkey flow proves the person, the session flow opens a session, and one commit stores both.

use auth_chad::core::Draws;
use auth_chad::passkey::{self, Assertion};
use auth_chad::session::{self, Bind, Opened};
use auth_chad::{Ctx, Error, Store};

async fn log_in<S: Store>(
    ctx: &Ctx<'_>,
    store: &S,
    draws: &mut impl Draws,
    ceremony: &str,
    assertion: &Assertion,
    jkt: [u8; 32],
) -> Result<Opened, Error> {
    let proved = passkey::login_finish(ctx, store, draws, ceremony, assertion).await?;
    let opened = session::open(ctx, store, draws, &proved.out, Bind::Key { jkt, native: false }).await?;
    let opened = opened.and(proved.writes);
    store.commit(opened.writes).await?;
    Ok(opened.out)
}

The axum adapter’s routes do this for you. Call flows directly only when you build your own routes.

Signup

The picture as text
sequenceDiagram
    participant B as Browser
    participant S as Server
    participant DB as Database
    B->>S: signup/start (invite, names)
    S-->>B: challenge, in a sealed ceremony token
    Note over B: the person creates a passkey
    B->>S: signup/finish (ceremony, new passkey, key proof)
    S->>S: check the passkey and the invite
    S->>DB: one commit: user, passkey, session, invite used, event, your rows (commit_signup)
    S-->>B: session
  • A ceremony takes two requests. Its state travels in a sealed token, and the challenge is marked as used at the end, so each ceremony works once.
  • Your commit_signup hook adds your own rows (a profile, a first project) to the same commit, or refuses the signup.

Login and fresh login

  1. login/start returns a challenge, and the person uses a passkey.
  2. login/finish verifies it and opens a session, bound to the client’s key (DPoP) or, for page loads, to a cookie.
  3. A risky action requires a fresh login: a passkey use within the last few minutes. Without one, the response is step_up_required, and the client asks for the passkey again (step-up).

Device login (CLI, app, machine)

The picture as text
sequenceDiagram
    participant D as Device (CLI)
    participant S as Server
    participant P as Person's browser
    D->>S: device_authorization (name, scope, its public key)
    S-->>D: device code + user code + link
    D->>P: shows the link and the code
    P->>S: opens the link, sees name, scope and address
    P->>S: approve (fresh login, your app data)
    S->>S: hooks: may_approve, device_kind, commit_approve
    loop until approved
        D->>S: token (device code, signed with its key)
    end
    S-->>D: key-bound token
  • A user device acts as the person. A machine acts as itself, with its own scopes.
  • The device holds no copyable secret: it signs every token request with its own key.

Recovery

MethodProofWorks with end-to-end encryption
Recovery keyThe person presents a key they storedYes: the key also opens its envelope
Tenant ownersOwners approveNo
EmailA mailed link, after a waiting periodNo

After a recovery, the account is on hold: old passkeys cannot be removed for a while. During the hold, the real owner can undo a recovery that a thief started. Undo removes everything added since the recovery: passkeys, sessions, devices, connected-app grants and API keys.

Connected apps (OAuth, MCP)

  1. The app sends the person to the login origin with a pushed authorization request.
  2. The person logs in and consents to named scopes, which creates a grant.
  3. The app receives short-lived tokens for one audience. These tokens cannot change passkeys, sessions or recovery.

After the commit: outbox and worker

work(&auth) runs every few seconds, in the web process or in a separate worker process. It:

  • removes expired rows (limits, single-use marks, sessions, codes);
  • sends mail from the outbox and retries failures;
  • runs place work (provision, remove).

Each piece of work holds a lease in the database, so two processes never run it at the same time.

Where the details are