Skip to main content

ApiKeyAuth

Trait ApiKeyAuth 

Source
pub trait ApiKeyAuth: Send + Sync {
    // Required methods
    async fn validate_api_key(
        &self,
        api_key: &str,
    ) -> AuthResult<TokenValidation>;
    async fn create_api_key(
        &self,
        user_id: &str,
        name: &str,
        expires_in: Option<u64>,
    ) -> AuthResult<String>;
    async fn revoke_api_key(&self, api_key: &str) -> AuthResult<()>;
    async fn list_api_keys(&self, user_id: &str) -> AuthResult<Vec<ApiKeyInfo>>;
}
Expand description

API Key 认证 trait

Required Methods§

Source

async fn validate_api_key(&self, api_key: &str) -> AuthResult<TokenValidation>

验证 API Key

§Arguments
  • api_key - API Key
Source

async fn create_api_key( &self, user_id: &str, name: &str, expires_in: Option<u64>, ) -> AuthResult<String>

创建 API Key

§Arguments
  • user_id - 用户 ID
  • name - Key 名称
  • expires_in - 过期时间 (秒),None 表示永不过期
Source

async fn revoke_api_key(&self, api_key: &str) -> AuthResult<()>

撤销 API Key

§Arguments
  • api_key - API Key
Source

async fn list_api_keys(&self, user_id: &str) -> AuthResult<Vec<ApiKeyInfo>>

列出用户的所有 API Key

§Arguments
  • user_id - 用户 ID

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§