authx-cli-0.1.2 is not a library.
authx-rs
An authentication and authorization framework for Rust.
Philosophy: Zero-cost abstractions, trait-based, async-native. Every feature is a plugin, nothing is hardcoded.
Architecture
┌───────────┐ ┌─────────────┐
│ authx-cli │ │ dashboard │
└─────┬─────┘ └──────┬──────┘
│ │
┌───────────────▼───────────────▼──────────────┐
│ authx-axum (HTTP layer) │
│ SessionLayer RateLimitLayer CSRF Routes │
└──────────────────────┬───────────────────────┘
│
┌─────────────────────────────▼─────────────────────────────┐
│ authx-plugins (features) │
│ │
│ EmailPassword TOTP MagicLink PasswordReset │
│ OAuth OIDC Provider/Federation WebAuthn │
│ ApiKey EmailOTP Admin Organization │
└─────────────────────────────┬─────────────────────────────┘
│
┌─────────────────────────────▼─────────────────────────────┐
│ authx-core (zero-dep engine) │
│ │
│ Crypto (Argon2id · AES-256-GCM) JWT / EdDSA signing │
│ RBAC + ABAC policy engine EventBus │
│ Brute-force lockout Key rotation │
└─────────────────────────────┬─────────────────────────────┘
│
┌─────────────────────────────▼─────────────────────────────┐
│ authx-storage (repository ports) │
│ │
│ MemoryStore (dev/test) PostgresStore (sqlx) │
│ AuditLogger RedisTokenStore │
│ 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
authx-cli/ # CLI binary (serve, migrate, user, key, oidc)
authx-dashboard/ # Admin dashboard (HTMX)
examples/
fullstack-app/ # End-to-end: React + Axum + PostgreSQL + SDK + TOTP MFA
axum-app/ # Full working Axum integration demo
actix-app/ # Direct actix-web integration demo
react-sdk-app/ # React consumer app for the TypeScript SDK packages
vue-sdk-app/ # Vue consumer app for the TypeScript SDK packages
packages/
authx-sdk-ts/ # Low-level TypeScript SDK: OIDC, JWKS, PKCE, device, session helpers
authx-sdk-web/ # Browser token storage, authenticated fetch, and refresh orchestration
authx-sdk-react/ # React provider/hooks for authx token clients
authx-sdk-vue/ # Vue plugin/composable for authx token clients
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
Contributing
Contributions are welcome! Please follow these steps:
- Fork and clone the repository.
- Create a branch from
mainfor your change. - Run the test suite before submitting:
- Open a pull request against
main. CI runs the same checks above — all must pass.
Guidelines
- Keep PRs focused — one feature or fix per PR.
- Add tests for new functionality. Existing plugins are good reference (
crates/authx-plugins/src/*/tests.rs). - Public API changes should update the relevant docs and README examples.
- Follow existing code style —
rustfmtdefaults, no unsafe unless strictly necessary. - Security-sensitive changes (crypto, session handling, token storage) require extra review. Please call this out in the PR description.
Reporting issues
Open an issue on GitHub. For security vulnerabilities, please email the maintainers directly instead of filing a public issue.