9 releases
Uses new Rust 2024
| 0.1.12 | Dec 17, 2025 |
|---|---|
| 0.1.11 | Nov 22, 2025 |
| 0.1.4 | Oct 16, 2025 |
#2212 in Authentication
420KB
5K
SLoC
sa-token-plugin-ntex
为 Ntex 框架提供 sa-token 认证和授权支持 Provides sa-token authentication and authorization support for Ntex framework
特性 | Features
- ✨ 一行导入所有功能 | One-line import for all functionalities
- 🔧 支持多种存储后端 | Support for multiple storage backends
- 🚀 简化的中间件集成 | Simplified middleware integration
- 📦 包含核心、宏、存储 | Includes core, macros, and storage
快速开始 | Quick Start
[dependencies]
sa-token-plugin-ntex = "0.1.5"
use sa_token_plugin_ntex::*;
use std::sync::Arc;
#[ntex::main]
async fn main() -> std::io::Result<()> {
let storage = Arc::new(MemoryStorage::new());
let state = SaTokenState::builder()
.storage(storage)
.timeout(7200)
.build();
ntex::web::HttpServer::new(move || {
ntex::web::App::new()
// 基础 token 提取中间件
.wrap(SaTokenMiddleware::new(state.clone()))
.route("/login", ntex::web::post().to(login_handler))
.service(
ntex::web::scope("/api")
// 需要登录的路由
.wrap(SaCheckLoginMiddleware::new(state.clone()))
.route("/user", ntex::web::get().to(user_handler))
.service(
ntex::web::scope("/admin")
// 需要管理员权限的路由
.wrap(SaCheckPermissionMiddleware::new(state.clone(), "admin"))
.route("/users", ntex::web::get().to(admin_users_handler))
)
)
})
.bind("127.0.0.1:8080")?
.run()
.await
}
sa-token-rust
已经转移到这个项目路径下了:https://github.com/click33/sa-token-rust
Dependencies
~22–43MB
~675K SLoC