Expand description
§sa-token-plugin-gotham
为 Gotham 框架提供 sa-token 认证和授权支持 Provides sa-token authentication and authorization support for Gotham 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-gotham = "0.1.5"ⓘ
use sa_token_plugin_gotham::*;
use gotham::router::Router;
use gotham::pipeline::{new_pipeline, single_pipeline};
use std::sync::Arc;
#[tokio::main]
async fn main() {
let storage = Arc::new(MemoryStorage::new());
let state = SaTokenState::builder()
.storage(storage)
.timeout(7200)
.build();
// 方式1:使用基础中间件 + 手动检查
let (chain, pipelines) = single_pipeline(
new_pipeline()
.add(SaTokenMiddleware::new(state.clone()))
.build()
);
// 方式2:使用登录检查中间件
let (chain, pipelines) = single_pipeline(
new_pipeline()
.add(SaCheckLoginMiddleware::new(state.clone()))
.build()
);
// 方式3:使用权限检查中间件
let (chain, pipelines) = single_pipeline(
new_pipeline()
.add(SaCheckPermissionMiddleware::new(state.clone(), "admin"))
.build()
);
let router = Router::new(chain, pipelines, |route| {
route.get("/api/user").to(user_handler);
route.get("/api/admin").to(admin_handler);
});
let addr = "127.0.0.1:8080";
gotham::start(addr, || Ok(router));
}Re-exports§
pub use layer::SaTokenLayer;pub use state::SaTokenState;pub use state::SaTokenStateBuilder;pub use wrapper::TokenValueWrapper;pub use wrapper::LoginIdWrapper;pub use sa_token_core;pub use sa_token_adapter;pub use adapter::*;pub use extractor::*;pub use middleware::*;
Modules§
Structs§
- Access
Token - Access Token Response | 访问令牌响应
- Auth
Result - Authentication result after processing 处理后的鉴权结果
- Authorization
Code - Authorization Code | 授权码
- Default
WsToken Extractor - Default token extractor implementation 默认的 Token 提取器实现
- Distributed
Session - Distributed session data structure 分布式 Session 数据结构
- Distributed
Session Manager - Distributed session manager 分布式 Session 管理器
- InMemory
Distributed Storage - In-memory distributed session storage implementation 内存分布式 Session 存储实现
- InMemory
Pusher - In-memory message pusher implementation 内存消息推送器实现
- JwtClaims
- JWT Claims | JWT 声明
- JwtManager
- JWT Manager | JWT 管理器
- Logging
Listener - 简单的日志监听器示例
- Memory
Storage - 内存存储实现
- Nonce
Manager - Nonce Manager | Nonce 管理器
- OAuth2
Client - OAuth2 Client Information | OAuth2 客户端信息
- OAuth2
Manager - OAuth2 Manager | OAuth2 管理器
- OAuth2
Token Info - OAuth2 Token Information (for storage) | OAuth2 令牌信息(用于存储)
- Online
Manager - Online user manager 在线用户管理器
- Online
User - Online user information 在线用户信息
- Path
Auth Config - Path-based authentication configuration 基于路径的鉴权配置
- Push
Message - Push message structure 推送消息结构
- Refresh
Token Manager - Refresh Token Manager | Refresh Token 管理器
- SaSession
- Session 对象 | Session Object
- SaToken
Config - sa-token 配置
- SaToken
Context - sa-token 上下文 | sa-token Context
- SaToken
Event - 事件数据
- SaToken
Event Bus - 事件总线 - 管理所有监听器并分发事件
- SaToken
Manager - sa-token 管理器
- Service
Credential - Service credential for inter-service authentication 服务间认证的服务凭证
- SsoClient
- SSO 客户端 | SSO Client
- SsoConfig
- SsoManager
- SsoServer
- SSO 服务端 | SSO Server
- SsoSession
- SSO 全局会话 | SSO Global Session
- SsoTicket
- SSO 票据结构 | SSO Ticket Structure
- StpUtil
- StpUtil - 权限认证工具类
- Token
Info - Token 信息 | Token Information
- Token
Value - Token 值
- WsAuth
Info - WebSocket authentication information WebSocket 认证信息
- WsAuth
Manager - WebSocket authentication manager WebSocket 认证管理器
Enums§
- JwtAlgorithm
- JWT Algorithm | JWT 算法
- Message
Type - Message type enumeration 消息类型枚举
- SaToken
Error - SaToken
Event Type - 事件类型
- Token
Style - Token 风格 | Token Style
Traits§
- Distributed
Session Storage - Distributed session storage trait 分布式 Session 存储 trait
- Framework
Adapter - 框架适配器trait
- Message
Pusher - Message pusher trait 消息推送器 trait
- Permission
Checker - 权限检查器 | Permission Checker
- SaStorage
- 存储适配器trait
- SaToken
Listener - 事件监听器 trait | Event Listener Trait
- WsToken
Extractor - Token extractor trait for WebSocket connections WebSocket 连接的 Token 提取器 trait
Functions§
- create_
context - Create SaTokenContext from authentication result 从鉴权结果创建SaTokenContext
- match_
any - Check if path matches any pattern in the list 检查路径是否匹配列表中的任意模式
- match_
path - Match a path against a pattern (Ant-style wildcard) 匹配路径与模式(Ant 风格通配符)
- need_
auth - Determine if authentication is needed for a path 判断路径是否需要鉴权
- process_
auth - Process authentication for a request path 处理请求路径的鉴权
Type Aliases§
Attribute Macros§
- sa_
check_ login - 检查登录状态的宏
- sa_
check_ permission - 检查权限的宏
- sa_
check_ permissions_ and - 同时检查多个权限(AND逻辑)
- sa_
check_ permissions_ or - 同时检查多个权限(OR逻辑)
- sa_
check_ role - 检查角色的宏
- sa_
check_ roles_ and - 同时检查多个角色(AND逻辑)
- sa_
check_ roles_ or - 同时检查多个角色(OR逻辑)
- sa_
ignore - 忽略认证检查的宏