Next Era Actix Web Authentication Macro
Next Era Solutions provides a procedural macro-based authentication system for Actix Web using JWT and API Key mechanisms.
✨ Features
- ✅ Simple attribute macros for securing routes:
#[authentication]— Validates access tokens.#[refresh_authentication]— Validates refresh tokens.#[x_api_key]— Validates API key headers.
- 🌍 Multilingual error messages (
en,zh-CN,th,mm). - 🔐 Environment variable-based secret management.
- 🔧 Easy to integrate with
actix_web.
🚀 Usage Example
use ;
use ;
async
async
async
✅ Environment Variables
| Variable | Description |
|---|---|
ACCESS_TOKEN_SECRET |
Secret key for validating JWT access tokens |
REFRESH_TOKEN_SECRET |
Secret key for validating JWT refresh tokens |
JWT_AUDIENCE |
Expected JWT audience claim |
X_API_KEY |
API key used in X-API-Key header |
Set these before running your application.
🧪 Tests
Unit tests demonstrate how the macros work:
async
async
⚠️ Considerations
- The current implementation uses
unwrap_or("")andexpect(). Add error handling before using in production. - Injects
HttpRequestautomatically into handlers — ensure compatibility with your handler signatures. - Requires
nextera_utilscrate for token validation.
📦 Cargo.toml Example
[]
= "4"
= { = "../nextera_utils" } # Or use crate version
= { = "../nextera_jwt" }
📜 License
MIT License © 2025 Next Era Solutions