r-token
r-token is a lightweight, zero-boilerplate authentication library designed for Rust and actix-web.
Inspired by the "parameter-as-authentication" pattern, it enables secure authentication by simply adding typed extractors to your route handlers.
Features
- Zero Boilerplate: No manual token validation or complex middleware configuration required.
- Type-Safe Authentication: Leverages Actix's
Extractormechanism. If anRUserparameter is present, the request is guaranteed to be authenticated. - Thread-Safe: Built on
ArcandMutexfor safe concurrent token management. - Non-Invasive: easily integrates into existing Actix applications.
Installation
Add r-token to your Cargo.toml:
[]
= "0.1"
= "4"
Quick Start
1. Implement Authentication Logic
No manual parsing is needed. Simply inject RUser into your protected handlers.
use ;
use ;
// --- Login Endpoint ---
// Injects the manager to generate and return a token
async
// --- Protected Endpoint ---
// The presence of RUser guarantees authentication.
// Unauthenticated requests are automatically rejected with 401 Unauthorized.
async
// --- Logout Endpoint ---
// Requires both Manager (state) and RUser (auth context)
async
2. Register and Run
Initialize RTokenManager and register it with your Actix application.
use ;
async
Usage Examples
Login
# Response: 550e8400-e29b-41d4-a716-446655440000
Access Protected Resource
# Without Token -> 401 Unauthorized
# With Token -> 200 OK
Roadmap
- Basic In-Memory Token Management
-
AuthorizationHeader Support - Token Expiration (TTL)
- Persistent Storage (Redis)
- Role-Based Access Control (RBAC)
- Cookie Support
License
MIT