pub trait Authenticator: Send + Sync {
// Required method
fn authenticate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
token: &'life1 str,
connection_id: &'life2 str,
device_info: Option<&'life3 DeviceInfo>,
metadata: Option<&'life4 HashMap<String, Vec<u8>>>,
) -> Pin<Box<dyn Future<Output = Result<AuthResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait;
// Provided methods
fn is_authenticated<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn revoke_authentication<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
认证器 Trait
实现此 trait 以提供自定义的 token 验证逻辑 例如:JWT 验证、数据库查询、Redis 验证等
Required Methods§
Sourcefn authenticate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
token: &'life1 str,
connection_id: &'life2 str,
device_info: Option<&'life3 DeviceInfo>,
metadata: Option<&'life4 HashMap<String, Vec<u8>>>,
) -> Pin<Box<dyn Future<Output = Result<AuthResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn authenticate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
token: &'life1 str,
connection_id: &'life2 str,
device_info: Option<&'life3 DeviceInfo>,
metadata: Option<&'life4 HashMap<String, Vec<u8>>>,
) -> Pin<Box<dyn Future<Output = Result<AuthResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Provided Methods§
Sourcefn is_authenticated<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn is_authenticated<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
检查连接是否已验证(可选,用于验证状态管理)
默认实现返回 true(假设验证通过后连接状态由 ConnectionManager 管理) 如果需要自定义验证状态管理(如 Redis、数据库),可以覆盖此方法
Sourcefn revoke_authentication<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn revoke_authentication<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
使连接失效(可选,用于主动撤销认证)
默认实现不做任何操作 如果需要支持主动撤销认证(如用户登出、token 撤销),可以覆盖此方法
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".