DOCS / FEATURES
Authentication
LaunchCrate authenticates each kind of caller with its own credential:
browser sessions for the SPA, JWTs with refresh tokens for API clients,
and API keys for machines acting for one org. The extractors in
api/src/auth/extract.rs resolve them, and the code lives in
api/src/auth/. People sign in with a password, a passkey, an emailed
magic link, Google/GitHub OAuth, or their organization's single sign-on.
| Credential | For | Carried as | Stored as |
|---|---|---|---|
| Opaque session | Browsers (the SPA) | session cookie: httpOnly, SameSite=Lax, Path=/ |
SHA-256 hash in sessions |
| JWT + refresh token | API and programmatic clients | Authorization: Bearer <jwt>; refresh token in an httpOnly refresh_token cookie scoped to /api/auth |
Refresh token hashed in refresh_tokens; the JWT isn't stored |
| API key | Machines acting for one org | X-Api-Key: rsk_... or Authorization: Bearer rsk_... |
SHA-256 hash in api_keys |
Every raw session, refresh token, and API key is 256 bits from the OS RNG. Only hashes reach the database, so a database leak exposes nothing usable.
Signing in
# Register (password: 8+ characters)
curl -X POST localhost:8787/api/auth/register \
-H 'content-type: application/json' \
-d '{"email":"ada@example.com","password":"correct horse","name":"Ada","mode":"session"}'
# Log in
curl -X POST localhost:8787/api/auth/login \
-H 'content-type: application/json' \
-d '{"email":"ada@example.com","password":"correct horse","mode":"session"}'mode picks the credential:
"session"sets thesessioncookie. The SPA always uses this."jwt"(the default) sets the rotatingrefresh_tokencookie.
Both return {"access_token": "...", "user": {...}}. Session clients
ignore the token. Accounts with two-factor enabled get
{"two_factor_required": true, "challenge_token": "..."} from login
instead (see Two-factor authentication).
Login never says which half was wrong: an unknown email burns the same Argon2 cost as a real check and answers "invalid email or password", and a disabled account is only revealed after a correct password. Accounts with no password (created through Google, GitHub, or SSO) get the same answer, after the same Argon2 cost, so the form can't reveal who signed up with a provider. When Google or GitHub is configured, the login page suggests the provider buttons whenever sign-in fails.
Passwords are hashed with Argon2id (64 MiB, 3 passes) inside
spawn_blocking, so hashing never stalls the async runtime. Verification
reads parameters from the stored hash, so old hashes keep working.
Browser sessions
api/src/auth/sessions.rs, api/src/auth/repo/sessions.rs.
- Sessions slide under a cap. A session is live while it's not revoked,
younger than
SESSION_ABSOLUTE_TTL_DAYS(30), and seen withinSESSION_IDLE_TTL_DAYS(14).last_seen_atis bumped at most once a minute per session, keeping the hot path read-only. - Revocation is instant. Every request checks the row, so revoking takes
effect on the next request. The lookup also joins
users, so disabling an account kills its sessions immediately. - Users can see their sessions. Each one records the User-Agent, and the settings page lists them and can revoke one or all others:
| Endpoint | Does |
|---|---|
GET /api/users/me/sessions |
Active sessions, most recent first, with current: true on the caller's |
DELETE /api/users/me/sessions/{id} |
Revoke one |
DELETE /api/users/me/sessions |
Sign out everywhere else: every other session, every refresh token, and every connected assistant (MCP) |
OAuth (Google, GitHub)
api/src/auth/oauth.rs. A provider is enabled when its
{GOOGLE,GITHUB}_CLIENT_ID and _CLIENT_SECRET are both set.
GET /api/auth/providers lists the enabled ones ({"oauth": ["google"]}),
and the login page shows a button only for those, or none at all. A
browser that follows a link to a disabled or unknown provider anyway is
sent back to {APP_URL}/login?error=oauth_unavailable.
GET /api/auth/oauth/{google|github}generates a PKCE pair and a CSRFstate, stores both in 10-minute httpOnly cookies scoped to/api/auth/oauth, and redirects to the provider.- The provider redirects to
{API_URL}/api/auth/oauth/{provider}/callback. The callback checksstate, exchanges the code with the PKCE verifier, and fetches the profile. - Only provider-verified emails are accepted (Google's
email_verified; GitHub's public address, which GitHub only allows once verified, or else its primary verified address). The next step links by email, so an unverified address could take over an existing local account. - The identity is linked to an existing account with the same email, or a new, pre-verified account is created (and gets the welcome email).
- The browser gets a session cookie and lands on
{APP_URL}/auth/callback, where the SPA loads/api/users/me.
Failures redirect to {APP_URL}/login?error=<reason>: oauth_denied,
oauth_invalid, oauth_expired, oauth_state_mismatch, oauth_failed
(the provider couldn't be reached or refused the code, and the cause is
logged), oauth_unavailable (the provider isn't configured),
oauth_email_unverified (the provider vouches for no email on
the account), account_disabled, or sso_required (the address's org
requires single sign-on). The SPA maps these to messages in
web/src/features/auth/AuthForm.tsx and shows them as a toast, except
sso_required, which stays beside the SSO form it points to.
Account lockout
Per-IP rate limits don't stop guessing spread over many addresses, so
each account also counts its wrong passwords (MAX_FAILED_LOGINS,
LOCKOUT_MINUTES, and LOCK_EMAIL_EVERY_HOURS in api/src/auth/mod.rs):
- The 10th wrong password in a row locks the account for 30 minutes,
and its owner gets an email (
email.account_locked) with a link to/unlock, which callsPOST /api/auth/unlockwith the token and ends the lock at once. - While locked, sign-in answers exactly like a wrong password, after the same Argon2 cost, even for the right password. The lock doesn't reveal that the account exists. The owner learns about it from the email.
- A successful sign-in, the unlock link, or a password reset clears the count. So does the lock running out: the next wrong password starts a new count, so one typo after a lockout doesn't lock the owner out again.
- Every lock can email the owner, but at most once every 6 hours
(
users.lock_notified_at). Someone who keeps locking an account can't flood the inbox, and a lockout that keeps coming back is still reported. - Only password sign-in counts. Magic links, OAuth, and SSO don't use a password, and the two-factor step has its own short-lived challenge.
- The superadmin panel shows a locked account with a "locked" marker
(
locked_untilin the account listing).
Rate limits
api/src/routes.rs wraps route groups in per-IP token buckets
(tower_governor). They are keyed on the client address that client_ip
resolves: TRUSTED_PROXY_HOPS entries from the right of
X-Forwarded-For, else the connection's, so a client can't choose its
bucket (see Org security policies).
| Routes | Refill | Burst |
|---|---|---|
/api/auth/* (sign-in, register, magic link, 2FA, reset, OAuth, SSO) |
1 request per second | 10 |
/api/users/*, /api/orgs/*, /api/admin/*, /api/invitations/*, /api/uploads/* |
20 requests per second | 100 |
/api/users/me/export, /api/orgs/{id}/export (on top of the above) |
1 request per second | 5 |
/api/webhooks/stripe, /api/webhooks/paddle, /api/webhooks/polar, /api/webhooks/lemonsqueezy |
20 requests per second | 300 |
/api/health, /api/openapi.json, /api/billing/plans, /api/billing/products, docs |
not limited | — |
Each limit is a RateLimit (requests per second and a burst), with the
shared ones named CREDENTIALS, SIGNED_IN and PROVIDER_WEBHOOKS in
api/src/routes.rs.
A person never hits the signed-in limit, but it stops scripted abuse
such as probing which emails have accounts via member-add. Over-limit
requests get 429. api/tests/rate_limits.rs checks the burst and the
refill rate. Behind a proxy, make sure it sets forwarding headers, or
every client shares the proxy's address.
[ full guide ]
The rest of this guide comes with the repo.
- Extractors
- Single sign-on
- Magic links
- JWT and refresh tokens
- Demo visitors
- Email verification
- Password reset
- Password change
- Email change
- CSRF
- New sign-in alerts
- Sign-up honeypot
- Endpoint summary