Next Era Actix Web Authentication Macro
This crate provides procedural macro attributes to easily secure Actix Web endpoints using JWTs and API keys. Developed by Next Era Solutions.
โจ Provided Macros
#[authentication]: Validates access tokens using theAuthorizationheader.#[refresh_authentication]: Validates refresh tokens using theAuthorizationheader.#[x_api_key]: Validates requests using theX-API-Keyheader.
๐ JWT Authentication Flow
- Extracts the token from
Authorization: Bearer <token>. - Loads secrets from environment:
ACCESS_TOKEN_SECRETREFRESH_TOKEN_SECRETJWT_AUDIENCE
- Uses
nextera_utils::jwt::validate_jwt()for validation. - Returns 401 or 419 (session expired) based on JWT errors.
- Injects
HttpRequestinto your handler function.
๐ Localization
Supports localization based on Content-Language header:
en(default)zh-CNthmm
๐งช Example Usage
use ;
use ;
async
async
async
โ Required Environment Variables
| Variable | Purpose |
|---|---|
ACCESS_TOKEN_SECRET |
Secret for validating access JWT |
REFRESH_TOKEN_SECRET |
Secret for validating refresh JWT |
JWT_AUDIENCE |
Audience claim for validation |
X_API_KEY |
API key expected in header |
โ ๏ธ Warnings
- Current version uses
unwrap_orandexpect(); improve error handling for production. - Automatically injects
HttpRequestas first argument in handler. - Requires
nextera_utilscrate.
๐ License
MIT License ยฉ 2025 Next Era Solutions