#authorization #token #security #web-token #web

sa-token-plugin-tide

Tide framework integration for sa-token-rust - All-in-one package

9 releases

Uses new Rust 2024

0.1.12 Dec 17, 2025
0.1.11 Nov 22, 2025
0.1.4 Oct 16, 2025

#2260 in Authentication

MIT/Apache

415KB
4.5K SLoC

sa-token-plugin-tide

为 Tide 框架提供 sa-token 认证和授权支持 Provides sa-token authentication and authorization support for Tide 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-tide = "0.1.8"
use std::sync::Arc;
use sa_token_plugin_tide::*;

#[async_std::main]
async fn main() -> tide::Result<()> {
    let storage = Arc::new(MemoryStorage::new());
    
    // 创建 Sa-Token 状态 | Create Sa-Token state
    let state = SaTokenState::builder()
        .token_name("Authorization")
        .timeout(7200)
        .storage(storage)
        .build();
    
    let mut app = tide::new();
    
    // 公共路由 | Public routes
    app.at("/login").post(login_handler);
    
    // 需要登录的路由 | Routes requiring login
    app.at("/user")
        .with(SaCheckLoginMiddleware::new(state.clone()))
        .get(user_info_handler);
    
    // 需要特定权限的路由 | Routes requiring specific permission
    app.at("/admin")
        .with(SaCheckPermissionMiddleware::new(state.clone(), "admin:access"))
        .get(admin_handler);
    
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}

Dependencies

~19–39MB
~504K SLoC