Start
[dependencies]
auth-chad = { git = "https://github.com/audiochad/auth-chad", rev = "<commit>", features = ["axum", "sqlite"] }
use std::{path::Path, sync::Arc};
use auth_chad::{Config, Prefix, axum::Auth, sqlite::SqliteStore};
fn auth(master: &[u8; 32]) -> Result<Arc<Auth<SqliteStore>>, Box<dyn std::error::Error>> {
let config = Config::new(
"myapp/v1", // never change it
"https://app.example.com", // where the API is
"app.example.com", // passkeys belong to this domain: never change it
"My app",
&["https://app.example.com"], // pages that may call the API
)?;
let store = SqliteStore::open(Path::new("/var/lib/myapp/app.db"), &Prefix::default(), 4)?;
Ok(Arc::new(Auth::new(config, master, store)?))
}
- Master key: 32 random bytes from a secret store. Never in the repository.
- Tables: run the migration as a deploy step, not at start.
auth-chad schema sqliteprints the SQL, andSqliteStore::create(path, prefix, readers, &[])runs it.opennever creates tables. Tenants and places are optional features: add them with&[Feature::Tenants]when you use them, and callauth.check_tables()at start. - Routes:
Router::new()….with_state(auth.clone()).merge(auth.router()). The API is below/auth. - Page:
import { signup, login, logout, session, stepUp } from "/auth/auth-chad.js". Call them from a click. - Behind a proxy:
with_proxies(n)(load-balancer). - A web app on another host (for example
app.example.comcallingapi.example.com): list its origin inConfigorigins (for passkeys) and inwith_web_origins(for CORS). Its calls carry no cookies, so it logs in with a key-bound token, for example with the Rust client. A key-bound policy refuses cookies everywhere. - No client addresses in audit events:
without_addresses(). Rate limits still use them. - Housekeeping: call
auth_chad::axum::work(&auth)every few seconds: it prunes, sends mails and runs places.
A whole application: rust/examples/minimal.