pub struct AuthenticationManager { /* private fields */ }Expand description
认证管理器
统一管理用户认证、Token 生成和验证
Implementations§
Source§impl AuthenticationManager
impl AuthenticationManager
Sourcepub fn with_config(
jwt_secret: &[u8],
access_expiration_secs: u64,
refresh_expiration_secs: u64,
) -> Self
pub fn with_config( jwt_secret: &[u8], access_expiration_secs: u64, refresh_expiration_secs: u64, ) -> Self
使用自定义配置创建认证管理器
Sourcepub async fn add_user(&self, user: User) -> AuthResult<()>
pub async fn add_user(&self, user: User) -> AuthResult<()>
添加或更新用户(直接插入已哈希的 User)
适用于测试/迁移场景。生产用户注册应使用 register_user,
后者会验证密码强度并自动哈希。
Sourcepub async fn register_user(
&self,
username: &str,
password: &str,
role: &str,
) -> AuthResult<()>
pub async fn register_user( &self, username: &str, password: &str, role: &str, ) -> AuthResult<()>
Sourcepub async fn authenticate(
&self,
credentials: AuthCredentials,
) -> AuthResult<String>
pub async fn authenticate( &self, credentials: AuthCredentials, ) -> AuthResult<String>
用户认证
验证用户凭据并生成 JWT Token
Sourcepub fn verify_token(&self, token: &str) -> AuthResult<JwtClaims>
pub fn verify_token(&self, token: &str) -> AuthResult<JwtClaims>
验证 JWT Token
Sourcepub fn refresh_token(&self, refresh_token: &str) -> AuthResult<String>
pub fn refresh_token(&self, refresh_token: &str) -> AuthResult<String>
刷新访问令牌
Sourcepub async fn get_user(&self, username: &str) -> AuthResult<User>
pub async fn get_user(&self, username: &str) -> AuthResult<User>
获取用户信息
Sourcepub async fn remove_user(&self, username: &str) -> AuthResult<()>
pub async fn remove_user(&self, username: &str) -> AuthResult<()>
删除用户
Auto Trait Implementations§
impl !RefUnwindSafe for AuthenticationManager
impl !UnwindSafe for AuthenticationManager
impl Freeze for AuthenticationManager
impl Send for AuthenticationManager
impl Sync for AuthenticationManager
impl Unpin for AuthenticationManager
impl UnsafeUnpin for AuthenticationManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request