Auth Middleware
JWT authentication middleware for Axum applications with built-in token validation and role-based access control support.
Features
- 🔐 JWT token validation
- 🛡️ Middleware integration with Axum
- 🎫 Support for Bearer and direct token formats
- ⚡ Configurable secret keys
- 👤 Claims extraction in handlers
- 🚀 Zero-boilerplate authentication
- 📦 Type-safe and ergonomic API
Installation
[]
= "0.1.0"
Quick Start
use ;
use ;
async
// Access claims in your handler
async
async
Token Format
The middleware accepts tokens in two formats:
- Bearer format:
Authorization: Bearer <token> - Direct format:
Authorization: <token>
Claims Structure
Error Responses
All errors return JSON responses:
Common error scenarios:
- Missing authorization header → 401 Unauthorized
- Invalid token format → 401 Unauthorized
- Expired token → 401 Unauthorized
- Invalid signature → 401 Unauthorized
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.