Crate sa_token_plugin_salvo

Crate sa_token_plugin_salvo 

Source
Expand description

§sa-token-plugin-salvo

为 Salvo 框架提供 sa-token 认证和授权支持 Provides sa-token authentication and authorization support for Salvo 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-salvo = "0.1.8"
use std::sync::Arc;
use sa_token_plugin_salvo::*;
 
#[tokio::main]
async fn main() {
    let storage = Arc::new(MemoryStorage::new());
     
    // 创建 Sa-Token 状态 | Create Sa-Token state
    let state = SaTokenState::builder()
        .token_name("Authorization")
        .timeout(7200)
        .storage(storage)
        .build();
     
    // 使用 Salvo 路由 | Use Salvo router
    let router = Router::new()
        // 公共路由 | Public routes
        .push(Router::with_path("login").post(login_handler))
        // 需要登录的路由 | Routes requiring login
        .push(Router::with_path("user")
            .hoop(SaCheckLoginMiddleware::new(state.clone()))
            .get(user_info_handler))
        // 需要特定权限的路由 | Routes requiring specific permission
        .push(Router::with_path("admin")
            .hoop(SaCheckPermissionMiddleware::new(state.clone(), "admin:access"))
            .get(admin_handler));
     
    Server::new(TcpListener::new("127.0.0.1:5800").bind().await)
        .serve(router)
        .await;
}

Re-exports§

pub use middleware::auth_middleware;
pub use middleware::permission_middleware;
pub use middleware::SaCheckLoginMiddleware;
pub use middleware::SaCheckPermissionMiddleware;
pub use middleware::SaCheckRoleMiddleware;
pub use layer::SaTokenLayer;
pub use layer::extract_token_from_request;
pub use state::SaTokenState;
pub use state::SaTokenStateBuilder;
pub use sa_token_core;
pub use sa_token_adapter;
pub use adapter::*;
pub use extractor::*;

Modules§

adapter
error
Error type definitions | 错误类型定义
extractor
layer
middleware
state
token
Token 管理模块

Structs§

AccessToken
Access Token Response | 访问令牌响应
AuthResult
Authentication result after processing 处理后的鉴权结果
AuthorizationCode
Authorization Code | 授权码
DefaultWsTokenExtractor
Default token extractor implementation 默认的 Token 提取器实现
DistributedSession
Distributed session data structure 分布式 Session 数据结构
DistributedSessionManager
Distributed session manager 分布式 Session 管理器
InMemoryDistributedStorage
In-memory distributed session storage implementation 内存分布式 Session 存储实现
InMemoryPusher
In-memory message pusher implementation 内存消息推送器实现
JwtClaims
JWT Claims | JWT 声明
JwtManager
JWT Manager | JWT 管理器
LoggingListener
简单的日志监听器示例
MemoryStorage
内存存储实现
NonceManager
Nonce Manager | Nonce 管理器
OAuth2Client
OAuth2 Client Information | OAuth2 客户端信息
OAuth2Manager
OAuth2 Manager | OAuth2 管理器
OAuth2TokenInfo
OAuth2 Token Information (for storage) | OAuth2 令牌信息(用于存储)
OnlineManager
Online user manager 在线用户管理器
OnlineUser
Online user information 在线用户信息
PathAuthConfig
Path-based authentication configuration 基于路径的鉴权配置
PushMessage
Push message structure 推送消息结构
RefreshTokenManager
Refresh Token Manager | Refresh Token 管理器
SaSession
Session 对象 | Session Object
SaTokenConfig
sa-token 配置
SaTokenContext
sa-token 上下文 | sa-token Context
SaTokenEvent
事件数据
SaTokenEventBus
事件总线 - 管理所有监听器并分发事件
SaTokenManager
sa-token 管理器
ServiceCredential
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 - 权限认证工具类
TokenInfo
Token 信息 | Token Information
TokenValue
Token 值
WsAuthInfo
WebSocket authentication information WebSocket 认证信息
WsAuthManager
WebSocket authentication manager WebSocket 认证管理器

Enums§

JwtAlgorithm
JWT Algorithm | JWT 算法
MessageType
Message type enumeration 消息类型枚举
SaTokenError
SaTokenEventType
事件类型
TokenStyle
Token 风格 | Token Style

Traits§

DistributedSessionStorage
Distributed session storage trait 分布式 Session 存储 trait
FrameworkAdapter
框架适配器trait
LoginId
LoginId trait - 支持任何可以转换为字符串的类型作为登录 ID
MessagePusher
Message pusher trait 消息推送器 trait
PermissionChecker
权限检查器 | Permission Checker
SaStorage
存储适配器trait
SaTokenListener
事件监听器 trait | Event Listener Trait
WsTokenExtractor
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§

SaTokenResult

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
忽略认证检查的宏