- apps/mail/Dockerfile + .dockerignore: rust:1-bookworm build -> debian slim runtime (pure rustls, only ca-certificates), dashboard baked in at /app/dashboard - RELAY_RETURN_PATH: fixed MAIL FROM for relays that only accept approved senders (OCI Email Delivery approves exact addresses, so per-email VERP is rejected); test mode keeps VERP so the simulated transport still recovers the email id - mail-auth keys: try hex first — 64 hex chars are also valid standard base64 (48 bytes), which made AUTH_SIGNING_KEY=<hex> fail at boot - Dodo webhook: an account_id from checkout metadata that does not exist is now ignored (200) instead of failing on the customer FK (500 + endless retries) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
mail-auth
Passwordless login for apps on Scribase Mail: magic links, 6-digit email codes,
email verification and password-reset links, all ending in a short-lived EdDSA
session JWT that apps verify against /.well-known/jwks.json (or by calling
POST /auth/token/verify).
Independent implementation, written without reference to useSend source.
Endpoints
| Method | Path | Purpose |
|---|---|---|
| POST | /auth/magic-link |
{email, redirect_to, project} → sends a 15-minute single-use link. Always 200. |
| POST | /auth/email-verification |
Same body; sends a confirm-your-email link. |
| POST | /auth/password-reset |
Same body; sends a reset link. The resulting JWT carries purpose: "password_reset". |
| GET | /auth/verify?token= |
Consumes a link token. Redirects to redirect_to#access_token=... or returns JSON when Accept: application/json. |
| POST | /auth/otp |
{email, project} → sends a 6-digit code, 10-minute TTL, 5 attempts. |
| POST | /auth/otp/verify |
{email, project, code} → {access_token, ...}. |
| POST | /auth/token/verify |
{token} → claims, for apps without a JWT library. |
| GET | /.well-known/jwks.json |
Ed25519 public key (OKP / EdDSA). |
| GET/POST | /auth/admin/projects |
List / create projects. Authorization: Bearer $AUTH_ADMIN_TOKEN. |
| GET/PATCH | /auth/admin/projects/{id} |
Read / update a project. |
Rate limits: 5 requests per hour per email per project, 30 per hour per IP
(Postgres counters, fixed hourly windows) → 429 with Retry-After.
Environment
| Variable | Default | Notes |
|---|---|---|
AUTH_SIGNING_KEY |
generated in dev | 32-byte Ed25519 seed, base64url (hex also accepted). Required when AUTH_ENV=production. |
AUTH_ADMIN_TOKEN |
unset → admin API returns 503 | Bearer token for project admin endpoints. |
AUTH_PUBLIC_BASE_URL |
http://127.0.0.1:8791 |
Used to build the links in emails. |
AUTH_ISSUER |
scribase-mail-auth |
JWT iss. |
AUTH_MAGIC_LINK_TTL_SECS |
900 |
|
AUTH_OTP_TTL_SECS |
600 |
|
AUTH_JWT_TTL_SECS |
3600 |
|
AUTH_OTP_MAX_ATTEMPTS |
5 |
|
AUTH_EMAIL_RATE_LIMIT |
5 |
per email per project per hour |
AUTH_IP_RATE_LIMIT |
30 |
per IP per hour |
AUTH_TRUST_PROXY |
false |
when true, read the client IP from X-Forwarded-For. |
Run the dev server
createdb mail_dev_auth
AUTH_ADMIN_TOKEN=dev-admin cargo run -p mail-auth --example dev_server
Mail is written to /tmp/mail-auth-outbox/<id>.eml instead of being sent.
Embedding
let state = mail_auth::AuthState::new(pool, sender, keys, config);
mail_auth::migrate(&pool).await?;
let app = other_router.merge(mail_auth::router(state));
All tables are prefixed auth_. Migrations use a timestamp version namespace
and ignore_missing, so they can share _sqlx_migrations with mail-core.