fastauth
Authentication for Rust web apps, modelled on Better Auth: one builder call gives you email and password sign-in, social login, sessions, and a plugin system for two-factor, organizations, admin tools, API keys, magic links, email codes, bearer tokens, JWTs, passkeys, usernames, anonymous users, multiple sessions and your own plugins. It runs on sqlx and axum out of the box, and the plugin API is checked by the compiler.
Status: 0.4.0 is on crates.io. It fixes two high-severity security issues that affect every
earlier version, adds the username, anonymous and multi-session plugins, and changes a few
defaults; read upgrading from 0.3 before you bump. The docs in
docs/ describe 0.4.
Install
Default features are axum, postgres and macros. Use sqlite instead of (or as well as)
postgres, and add oauth for GitHub and Google sign-in, two-factor for TOTP, email codes and
backup codes, organization, admin, api-key, magic-link, email-otp, bearer, jwt,
passkey, username, anonymous and multi-session for those plugins, and cli for the migration commands. Requires Rust 1.94 or newer.
Example
use SocketAddr;
use get;
use ;
use TwoFactor;
use *;
use ;
use Serialize;
pub type AppAuth = >;
async
async
If you remove TwoFactor from the builder, session.user.plugin::<TwoFactor, _>()
stops compiling and tells you which plugin is missing. crates/fastauth/examples/ has runnable
apps on SQLite and in memory.
Crates
| Crate | What |
|---|---|
fastauth |
The crate apps depend on: re-exports everything below behind features |
fastauth-core |
Builder, compile-checked plugin list, sessions, crypto, routing, email and password, verification, reset |
fastauth-axum |
auth.router(), Session / FreshSession extractors, the session layer |
fastauth-sqlx |
Postgres and SQLite adapter, migrations, shared transactions (.in_tx) |
fastauth-macros |
#[derive(Fields, Model, AuthError)] |
fastauth-oauth |
The Social plugin: GitHub and Google |
fastauth-plugin-two-factor |
TOTP, email codes, backup codes, trusted devices |
fastauth-plugin-organization |
Organizations, members, invitations, roles and permissions, axum extractors (0.2) |
fastauth-plugin-admin |
User management, roles and permissions, bans, impersonation, RequireRole (0.2) |
fastauth-plugin-api-key |
Hashed API keys with expiry, usage and rate limits, permissions, optional sessions from keys (0.2) |
fastauth-plugin-magic-link |
Sign-in links by email, with sign-up on first use (0.3) |
fastauth-plugin-email-otp |
One-time codes by email for sign-in, email verification and password reset (0.3) |
fastauth-plugin-bearer |
Sessions from Authorization: Bearer, and the set-auth-token header (0.3) |
fastauth-plugin-jwt |
JWTs for signed-in users, a JWKS with rotating keys, JwksVerifier for other services (0.3) |
fastauth-plugin-passkey |
Passkeys (WebAuthn) on webauthn-rs: registration, sign-in, management (0.3) |
fastauth-plugin-username |
Usernames next to emails, sign-in by username, availability checks (0.4) |
fastauth-plugin-anonymous |
Anonymous users, linked to the real account they sign up or in with (0.4) |
fastauth-plugin-multi-session |
Several signed-in accounts per browser, switching between them (0.4) |
fastauth-cli |
fastauth secret; schema and migration commands run from your app via fastauth::cli::run |
The HTTP API is compatible with Better Auth's TypeScript client (tested against
better-auth 1.7.28, see docs/11), so its React, Vue and
Svelte clients work against a fastauth server.
Not built yet: other plugins, teams in organizations, actix-web, Redis and MySQL. Overview lists what's planned.
Docs
| Page | What it covers |
|---|---|
| Overview | Goals, non-goals, crate layout, feature flags, the main design decisions, what's planned |
| Quickstart | From cargo new to sign-up, sign-in and a protected route |
| Configuration | Every builder option: secrets, email and password, social providers, sessions, cookies, rate limits, ids |
| Sessions and the server API | Extractors, typed user fields, calling auth from your own code |
| Plugins | Using plugins, and writing one: schema, endpoints, hooks, events, errors, dependencies |
| Databases | sqlx, the schema, ids, migrations, typed queries, writing an adapter |
| HTTP integrations | axum, tower, the outgoing HTTP client, writing an integration |
| Internals | How it works: the type-level plugin list, the build step, the request path, the session hot path |
| Security | Tokens, cookies, password hashing, CSRF, OAuth, rate limiting, secret rotation |
| Decisions | The design decisions, including the ones made since 0.1 |
| Better Auth's client | Using better-auth/client with fastauth, the tested versions, known gaps |
| Organization | Organizations, members, invitations, roles and permissions, extractors |
| Admin | User management, roles and permissions, bans, impersonation, RequireRole |
| API keys | Hashed API keys, limits, permissions, sessions from keys |
| Magic links | Sign-in links by email, redirects, sign-up on first use |
| Email OTP | One-time codes by email for sign-in, email verification and password reset |
| Bearer tokens | Sessions from Authorization: Bearer for clients without cookies |
| JWT | Tokens and a JWKS for other services, key rotation, verifying tokens elsewhere |
| Passkeys | WebAuthn registration and sign-in, the passkey table, managing passkeys |
| Usernames | Usernames on sign-up and update-user, sign-in by username, validation and normalization |
| Anonymous users | Guest sign-in, linking to the real account, deleting anonymous users |
| Multiple sessions | Several accounts per browser, device-session cookies, switching and revoking |
Agent skill
skills/use-fastauth teaches coding agents to use fastauth
in their own apps: setup, axum, migrations, user fields, the first-party plugins, the server
API, custom plugins and tests, plus the compiler errors they'll meet. Every code sample in it
compiles against main (0.4). Copy the folder into your agent's skills directory (for Claude Code,
.claude/skills/use-fastauth/).
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.