Skip to main content

AuthService

Trait AuthService 

Source
pub trait AuthService: Send + Sync {
Show 15 methods // Required methods async fn login(&self, credentials: &Credentials) -> AuthResult<AuthToken>; async fn logout(&self, token: &str) -> AuthResult<()>; async fn refresh_token(&self, refresh_token: &str) -> AuthResult<AuthToken>; async fn validate_token(&self, token: &str) -> AuthResult<TokenValidation>; async fn create_user( &self, request: &CreateUserRequest, ) -> AuthResult<UserInfo>; async fn get_user(&self, user_id: &str) -> AuthResult<UserInfo>; async fn update_user( &self, user_id: &str, request: &UpdateUserRequest, ) -> AuthResult<UserInfo>; async fn delete_user(&self, user_id: &str) -> AuthResult<()>; async fn change_password( &self, user_id: &str, request: &ChangePasswordRequest, ) -> AuthResult<()>; async fn reset_password(&self, identifier: &str) -> AuthResult<()>; async fn check_permission( &self, user_id: &str, permission: &str, ) -> AuthResult<bool>; async fn get_user_roles(&self, user_id: &str) -> AuthResult<Vec<Role>>; async fn assign_role(&self, user_id: &str, role_id: &str) -> AuthResult<()>; async fn remove_role(&self, user_id: &str, role_id: &str) -> AuthResult<()>; fn config(&self) -> &AuthConfig;
}
Expand description

认证服务 trait

Required Methods§

Source

async fn login(&self, credentials: &Credentials) -> AuthResult<AuthToken>

用户登录

§Arguments
  • credentials - 用户凭证
§Returns

认证 Token

Source

async fn logout(&self, token: &str) -> AuthResult<()>

用户登出

§Arguments
  • token - 访问令牌
Source

async fn refresh_token(&self, refresh_token: &str) -> AuthResult<AuthToken>

刷新 Token

§Arguments
  • refresh_token - 刷新令牌
Source

async fn validate_token(&self, token: &str) -> AuthResult<TokenValidation>

验证 Token

§Arguments
  • token - 访问令牌
Source

async fn create_user(&self, request: &CreateUserRequest) -> AuthResult<UserInfo>

创建用户

§Arguments
  • request - 创建请求
Source

async fn get_user(&self, user_id: &str) -> AuthResult<UserInfo>

获取用户信息

§Arguments
  • user_id - 用户 ID
Source

async fn update_user( &self, user_id: &str, request: &UpdateUserRequest, ) -> AuthResult<UserInfo>

更新用户信息

§Arguments
  • user_id - 用户 ID
  • request - 更新请求
Source

async fn delete_user(&self, user_id: &str) -> AuthResult<()>

删除用户

§Arguments
  • user_id - 用户 ID
Source

async fn change_password( &self, user_id: &str, request: &ChangePasswordRequest, ) -> AuthResult<()>

修改密码

§Arguments
  • user_id - 用户 ID
  • request - 密码修改请求
Source

async fn reset_password(&self, identifier: &str) -> AuthResult<()>

重置密码

§Arguments
  • identifier - 用户标识 (用户名/邮箱/手机号)
Source

async fn check_permission( &self, user_id: &str, permission: &str, ) -> AuthResult<bool>

验证用户权限

§Arguments
  • user_id - 用户 ID
  • permission - 权限代码
Source

async fn get_user_roles(&self, user_id: &str) -> AuthResult<Vec<Role>>

获取用户角色

§Arguments
  • user_id - 用户 ID
Source

async fn assign_role(&self, user_id: &str, role_id: &str) -> AuthResult<()>

分配角色

§Arguments
  • user_id - 用户 ID
  • role_id - 角色 ID
Source

async fn remove_role(&self, user_id: &str, role_id: &str) -> AuthResult<()>

移除角色

§Arguments
  • user_id - 用户 ID
  • role_id - 角色 ID
Source

fn config(&self) -> &AuthConfig

获取配置

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§