r-token
r-token is a small, in-memory token authentication helper for Rust + actix-web.
It follows a “parameter-as-authentication” style: add RUser to your handler parameters, and the request is authenticated automatically via Actix extractors.
Features
- Zero boilerplate: no custom middleware required for basic header auth.
- Extractor-first: declaring
RUserprotects the route. - Thread-safe, shared state:
RTokenManagerisCloneand shares an in-memory store. - TTL support: tokens expire based on a per-login TTL (seconds).
Installation
Add r-token to your Cargo.toml:
[]
= "0.1"
Quick Start
1. Add endpoints
No manual header parsing is needed. Inject RUser into protected handlers.
use ;
use ;
async
async
async
2. Register and Run
Initialize RTokenManager and register it with your Actix application.
use ;
use RTokenManager;
async
Authorization header
The extractor reads the token from Authorization and supports:
Authorization: <token>
Authorization: Bearer <token>
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