authx-cli-0.1.0 is not a library.
authx-rs
A production-grade authentication and authorization framework for Rust, built for Axum.
Philosophy: Zero-cost abstractions, trait-based, async-native. Every feature is a plugin, nothing is hardcoded.
Architecture
┌─────────────────────────────────────────────────────┐
│ authx-axum (HTTP Layer) │
│ SessionLayer · RateLimitLayer · CSRF · Handlers │
└──────────────────────┬──────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────┐
│ authx-plugins (Features) │
│ EmailPassword · TOTP · MagicLink · PasswordReset │
│ Admin · (OAuth — upcoming) │
└──────────────────────┬──────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────┐
│ authx-core (Zero-dep engine) │
│ Crypto · JWT/EdDSA · RBAC · ABAC · Events │
│ Brute-force lockout · Key rotation │
└──────────────────────┬──────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────┐
│ authx-storage (Repository ports) │
│ MemoryStore (tests) · PostgresStore (sqlx) │
│ AuditLogger · Bring your own adapter │
└─────────────────────────────────────────────────────┘
Design constraints
| Constraint | Detail |
|---|---|
| Framework-agnostic core | authx-core has zero axum/actix imports |
| Storage-agnostic | Pluggable Repository traits; bring your own adapter |
| Password hashing | Argon2id only (65536 mem / 3 iter / 4 parallelism) |
| Session tokens | SHA-256 hashed before storage, raw token sent to client once |
| JWT signing | Ed25519 / EdDSA via jsonwebtoken |
| CSRF | Origin/Referer trusted-origin check for mutating requests |
Workspace layout
crates/
authx-core/ # Models, crypto, events, RBAC/ABAC policy, identity
authx-storage/ # Repository traits + MemoryStore + PostgresStore
authx-plugins/ # Plugin trait + all auth plugins
authx-axum/ # Tower middleware, route handlers, cookies, CSRF, rate limiting
examples/
axum-app/ # Full working integration demo
Quickstart
# Cargo.toml
[]
= "0.1"
= "0.1"
= "0.1"
= "0.1"
use MemoryStore;
use EmailPasswordService;
use ;
use EventBus;
use ;
async
See examples/axum-app/src/main.rs for a complete example.
Features
Email + Password authentication
use EmailPasswordService;
use LockoutConfig;
// Basic setup
let svc = new;
// With brute-force lockout (5 failures → 15-min lockout)
let svc = new
.with_lockout;
let resp = svc.sign_up.await?;
let resp = svc.sign_in.await?;
// resp.token — JWT, send to client
// resp.session — full Session model
TOTP MFA
use TotpService;
let svc = new;
// Enrollment
let setup = svc.begin_setup.await?;
// setup.otpauth_uri → generate QR code, show to user
// setup.backup_codes → show once, store securely
// Confirm user can produce a valid code, then persist
svc.confirm_setup.await?;
// Verify on sign-in
svc.verify.await?;
Magic link authentication
use MagicLinkService;
let svc = new;
// Issue token (send in email yourself — authx does not send email)
let token = svc.request_link.await?; // None if unknown
// User clicks link → verify and create session
let resp = svc.verify.await?;
// resp.token → JWT session token
Password reset
use PasswordResetService;
let svc = new;
// 30-minute token (send in email yourself)
let token = svc.request_reset.await?; // None if unknown
// User submits new password
svc.reset_password.await?;
Admin operations
use AdminService;
let svc = new;
svc.ban_user.await?;
svc.unban_user.await?;
// Impersonate — creates a tagged session for support/debugging
let = svc.impersonate.await?;
RBAC + ABAC authorization
use ;
use ;
let mut engine = new;
engine.add_policy;
engine.add_policy;
engine.add_policy;
// engine.add_policy(TimeWindowPolicy::weekdays(9, 18)); // 09–18 UTC, Mon–Fri
// Enforce — returns Err(AuthError::Forbidden) on denial
engine.enforce.await?;
Key rotation (zero-downtime)
use KeyRotationStore;
let store = new; // keep at most 3 key versions
store.add_key?;
// Later — rotate without dropping existing token validity
store.rotate?;
let token = store.sign?;
let claims = store.verify?; // tries v2 first, falls back to v1
Rate limiting
use RateLimitLayer;
use Duration;
// 20 requests per minute per IP on auth routes
let rate_limit = new;
let auth_routes = new
.nest
.layer;
Audit logging
use AuditLogger;
// Subscribes to EventBus and writes every auth event to storage asynchronously.
new.run;
// Query logs
let logs = store.find_audit_logs_by_user.await?;
Storage adapters
In-memory (tests / development)
use MemoryStore;
let store = new;
PostgreSQL (production)
= { = "0.1", = ["sqlx-postgres"] }
use PostgresStore;
let store = connect.await?;
store.migrate.await?; // runs bundled migrations automatically
Security defaults
| Concern | Default |
|---|---|
| Password hashing | Argon2id · m=65536 · t=3 · p=4 |
| JWT algorithm | EdDSA (Ed25519) |
| Session token storage | SHA-256 hex hash only — plaintext discarded immediately |
| OAuth token storage | AES-256-GCM encrypted |
| CSRF protection | Origin/Referer trusted-origin check on all mutating methods |
| Brute-force lockout | Sliding window — configurable threshold + window |
| Rate limiting | Per-IP sliding window — configurable threshold + window |
| Magic link TTL | 15 minutes, single-use |
| Password reset TTL | 30 minutes, single-use |
| Cookie flags | HttpOnly · SameSite=Lax · Secure (configurable) · Path=/ |
Running tests
Roadmap
v0.1 (released)
- Email + password authentication with Argon2id
- TOTP MFA with backup codes
- Magic link authentication
- Password reset
- API key authentication
- OAuth2 authorization code flow with PKCE
- Email verification
- Organization management + RBAC
- ABAC policy engine with built-in policies
- Brute-force lockout + per-IP rate limiting
- CSRF protection
- JWT key rotation (zero-downtime, Ed25519)
- Audit logging
- PostgreSQL adapter (sqlx 0.8)
- Admin service (ban, impersonate, revoke sessions)
- Admin dashboard (HTMX)
- CLI (
authx serve,migrate,user,key)
v0.2 (planned)
- OIDC Provider — act as an identity provider
- OAuth2 Provider — act as an authorization server
- SSO / OIDC federation — sign in via Okta, Azure AD, Google Workspace
- Device Authorization Grant (RFC 8628)
- SAML 2.0 — enterprise IdP integration
- SCIM 2.0 — user and group provisioning
- WebAuthn / Passkey plugin
- Redis-backed rate limiting and token store
- Organization invitation flow