🛡️ Next Era Actix Web Authentication Macros
Procedural macro attributes for seamless JWT and API key-based authentication in Actix Web, developed by Next Era Solutions.
✨ Overview
This crate provides three procedural macro attributes:
#[authentication]— Validates an Access Token.#[refresh_authentication]— Validates a Refresh Token.#[x_api_key]— Validates a request using an X-API-Key.
All three macros inject an actix_web::HttpRequest into your handler, extract headers, validate secrets, and return an Unauthorized response if validation fails.
🚀 Usage
1. Add dependencies
Add the following to your Cargo.toml:
[]
= "4"
= { = "../nextera_utils" } # adjust as needed
Add the macro crate as a dependency:
[]
= true
2. Define Handlers
use ;
use ;
pub async
async
async
async
async
🧠 How It Works
Each macro:
- Extracts the corresponding header from
HttpRequest. - Parses the header for the token or key.
- Validates it using:
nextera_utils::jwt::validate_jwtfor JWT tokens.- Direct comparison for
X_API_KEY.
- If validation fails, responds with:
Supports language-specific messages in:
- English (default)
- Chinese (zh-CN)
- Thai (th)
- Burmese (mm)
⚠️ Important Notes
- Async Support: All macros work on async handlers.
- HttpRequest Injection:
HttpRequestis auto-injected as the first argument. - Error Handling: Currently uses
.unwrap_or("")and.expect. Improve error handling for production use. - Environment Variables:
ACCESS_TOKEN_SECRETREFRESH_TOKEN_SECRETX_API_KEY
- Dependency: Requires
nextera_utilscrate for JWT handling and shared types.
📂 Project Structure
nextera_jwt/
├── src/
│ ├── lib.rs # Procedural macro implementations
├── Cargo.toml
├── README.md
📜 License
This project is licensed under the MIT License. Free for personal and commercial use.
👨💻 Developed By
Next Era Solutions
Crafting secure and modular backend solutions for modern Rust web apps.