| Crates.io | authrs |
| lib.rs | authrs |
| version | 0.1.2 |
| created_at | 2025-11-25 17:46:22.295142+00 |
| updated_at | 2025-12-27 06:39:49.752546+00 |
| description | A comprehensive authentication library for Rust |
| homepage | |
| repository | https://github.com/LioRael/authrs |
| max_upload_size | |
| id | 1950162 |
| size | 765,716 |
AuthRS is a Rust 2024 authentication toolkit that consolidates password hashing, JWT/session tokens, MFA, passwordless (Magic Link / OTP), OAuth2 clients, RBAC, WebAuthn/Passkeys, CSRF, rate limiting, and secure randomness utilities so you can assemble robust auth flows without re-implementing primitives.
argon2, bcrypt, scrypt, jwt, mfa, api-key, passwordless, crypto, oauth, rbac, webauthn, full)src/
lib.rs # Library entry + public exports
main.rs # Minimal binary stub for manual experiments
error.rs # Shared Error/Result definitions
password/ # Hashers + strength rules
token/ # jwt.rs, refresh.rs, session.rs
mfa/ # TOTP/HOTP + recovery modules
passwordless/ # Magic Link & OTP helpers
oauth/ # OAuth2 clients, PKCE, token handling
rbac/ # Role/policy helpers
webauthn/ # Passkey flows and validation
crypto/ # HKDF key derivation helpers
api_key/ # API key lifecycle management
security/ # csrf.rs, rate_limit.rs, account.rs (lockout), cookie.rs
random.rs # Secure RNG helpers
audit.rs # Security event logging utilities
cargo add authrs # Add as a dependency
cargo build # Build with default features
cargo test --features full # Run tests with all modules
Use --no-default-features --features <list> to mix modules precisely (e.g., cargo build --no-default-features --features jwt,passwordless).
use authrs::password::hash_password;
use authrs::token::jwt::{JwtBuilder, JwtValidator};
let hash = hash_password("Str0ng_P@ss")?;
let token = JwtBuilder::new()
.subject("user123")
.issuer("authrs-demo")
.expires_in_hours(24)
.build_with_secret(b"my-secret-key-at-least-32-bytes!")?;
let claims = JwtValidator::new(b"my-secret-key-at-least-32-bytes!").validate(&token)?;
println!("subject={}", claims.sub.unwrap_or_default());
argon2, jwt, mfabcrypt, scrypt, oauth, rbac, webauthn, passwordless, crypto, api-keyfull turns on every optional module (including OAuth, RBAC, WebAuthn)cargo build --no-default-features --features jwt,scryptcargo fmt # Format with rustfmt
cargo clippy --all-targets --all-features # Run static analysis
cargo test --features full # Execute full-feature test suite
cargo doc --open # Build API docs
Place unit tests alongside modules, and integration tests under tests/ when composing flows. Prefer deterministic RNG (StdRng::seed_from_u64) for assertions; reserve OsRng for production randomness. Use feature-specific flags to validate gated paths (e.g., --features oauth or --features webauthn).
constant_time_compare from random.rs when comparing secrets.MIT License — see LICENSE for the full text.