authbox
A lightweight, modular authentication framework for Rust built around traits, async support, and pluggable components.
It provides
- Password hashing (Argon2)
- JWT authentication (access + refresh tokens)
- Async-ready API (Tokio)
- Pluggable architecture (store, hasher, token manager)
- Fully testable design
Features
- User registration & login flow
- Secure password hashing using Argon2
- JWT access + refresh token support
- Token refresh rotation
- Custom user store support (DB or in-memory)
- Fully async (tokio + async-trait)
- Trait-based architecture for flexibility
Installation
Quick Start
- Import prelude
use *;
- Create JWT manager
You can use the default DefaultJwtManager or use yours by implemting the TokenManager trait
For example we use the DefaultJwtManager
let tokens = new;
- Create password hasher
You can use the default DefaultHasher or use yours by implemting the PasswordHasher trait
For example we use the DefaultJwtManager
let hasher = DefaultHasher;
- Implement a user store
You can use your DB or in-memory store. and must implement the UserStrore<U: YourCustomUserType> and YourCustomUserType must implement the AuthUser trait;
Example:
; // Must implemt the >>>> UserStrore<U: YourCustomUserType>`
- Create AuthService
let store = new;
let tokens = new;
let hasher = DefaultHasher;
let mut auth = AuthService ;
6 Register User
let user = auth
.
.await;
println!;
}
7 Login User
let login = auth
.
.await?;
if let Some = login
8 Refresh Token
let new_tokens = auth
.tokens
.refresh
.await?;
println!;
Token Structure
Architecture
authbox is built using traits:
AuthService
Handles business logic:
- register
- login
TokenManager
Handles JWT:
- generate
- verify
- refresh
PasswordHasher
Handles password security:
- hash
- verify
UserStore
Handles persistence:
- create user
- find user
Roadmap
- Database adapters (SQLx, MongoDB)
- Token revocation list
- Role-based access control (RBAC)
- OAuth2 integration
- Middleware for Actix / Axum
- Redis session support
License
Apache-2.0