sa_token_plugin_ntex/
lib.rs

1// Author: 金书记
2//
3// 中文 | English
4// Ntex 框架集成 | Ntex Framework Integration
5//
6//! # sa-token-plugin-ntex
7//! 
8//! 为 Ntex 框架提供 sa-token 认证和授权支持
9//! Provides sa-token authentication and authorization support for Ntex framework
10//! 
11//! ## 特性 | Features
12//! 
13//! - ✨ 一行导入所有功能 | One-line import for all functionalities
14//! - 🔧 支持多种存储后端 | Support for multiple storage backends
15//! - 🚀 简化的中间件集成 | Simplified middleware integration
16//! - 📦 包含核心、宏、存储 | Includes core, macros, and storage
17//! 
18//! ## 快速开始 | Quick Start
19//! 
20//! ```toml
21//! [dependencies]
22//! sa-token-plugin-ntex = "0.1.5"
23//! ```
24//! 
25//! ```rust,ignore
26//! use sa_token_plugin_ntex::*;
27//! use std::sync::Arc;
28//! 
29//! #[ntex::main]
30//! async fn main() -> std::io::Result<()> {
31//!     let storage = Arc::new(MemoryStorage::new());
32//!     let state = SaTokenState::builder()
33//!         .storage(storage)
34//!         .timeout(7200)
35//!         .build();
36//!     
37//!     ntex::web::HttpServer::new(move || {
38//!         ntex::web::App::new()
39//!             // 基础 token 提取中间件
40//!             .wrap(SaTokenMiddleware::new(state.clone()))
41//!             .route("/login", ntex::web::post().to(login_handler))
42//!             .service(
43//!                 ntex::web::scope("/api")
44//!                     // 需要登录的路由
45//!                     .wrap(SaCheckLoginMiddleware::new(state.clone()))
46//!                     .route("/user", ntex::web::get().to(user_handler))
47//!                     .service(
48//!                         ntex::web::scope("/admin")
49//!                             // 需要管理员权限的路由
50//!                             .wrap(SaCheckPermissionMiddleware::new(state.clone(), "admin"))
51//!                             .route("/users", ntex::web::get().to(admin_users_handler))
52//!                     )
53//!             )
54//!     })
55//!     .bind("127.0.0.1:8080")?
56//!     .run()
57//!     .await
58//! }
59//! ```
60
61pub mod adapter;
62pub mod extractor;
63pub mod middleware;
64pub mod layer;
65pub mod state;
66
67// 重新导出核心功能 | Re-export core functionalities
68pub use sa_token_core::{self, SaTokenManager, StpUtil, SaTokenConfig, TokenValue, TokenInfo, 
69    SaSession, PermissionChecker, SaTokenError, SaTokenEvent, SaTokenListener, SaTokenEventBus, LoggingListener,
70    JwtManager, JwtClaims, JwtAlgorithm, OAuth2Manager, OAuth2Client, AuthorizationCode, AccessToken, OAuth2TokenInfo,
71    NonceManager, RefreshTokenManager, WsAuthManager, WsAuthInfo, WsTokenExtractor, DefaultWsTokenExtractor,
72    OnlineManager, OnlineUser, PushMessage, MessageType, MessagePusher, InMemoryPusher,
73    DistributedSessionManager, DistributedSession, DistributedSessionStorage, ServiceCredential, InMemoryDistributedStorage,
74    config::TokenStyle, token, error};
75
76pub use sa_token_adapter::{self, storage::SaStorage, framework::FrameworkAdapter};
77pub use sa_token_macro::*;
78
79// 重新导出存储实现(通过 feature 控制)
80// Re-export storage implementations (controlled by features)
81#[cfg(feature = "memory")]
82pub use sa_token_storage_memory::*;
83
84#[cfg(feature = "redis")]
85pub use sa_token_storage_redis::*;
86
87#[cfg(feature = "database")]
88pub use sa_token_storage_database::*;
89
90// 重新导出本模块的适配器 | Re-export adapters from this module
91pub use adapter::*;
92pub use extractor::*;
93pub use middleware::*;
94pub use layer::SaTokenLayer;
95pub use state::{SaTokenState, SaTokenStateBuilder};
96