pub struct JwtAuthenticator { /* private fields */ }Expand description
Authenticator that issues and verifies real HS256 JWTs.
Implementations§
Source§impl JwtAuthenticator
impl JwtAuthenticator
Sourcepub const MIN_SECRET_LEN: usize = 32
pub const MIN_SECRET_LEN: usize = 32
HS256 最小密钥长度(v4.8.0 修复 M-15)
修复前默认路径无密钥强度校验——短密钥/常见口令可被 GPU 离线爆破 (数十亿次/秒),攻击者获取任一令牌即可枚举密钥并任意伪造 claims。
Sourcepub fn new(
secret: impl Into<String>,
issuer: impl Into<String>,
expiration: u64,
) -> JwtAuthenticator
pub fn new( secret: impl Into<String>, issuer: impl Into<String>, expiration: u64, ) -> JwtAuthenticator
创建认证器(兼容旧签名,不做密钥强度校验)
生产环境必须使用 JwtAuthenticator::try_new——本构造器保留
兼容性(测试/低风险场景),弱密钥风险见 M-15。
Sourcepub fn try_new(
secret: impl Into<String>,
issuer: impl Into<String>,
expiration: u64,
) -> Result<JwtAuthenticator, AuthError>
pub fn try_new( secret: impl Into<String>, issuer: impl Into<String>, expiration: u64, ) -> Result<JwtAuthenticator, AuthError>
创建认证器并强制校验密钥强度(v4.8.0 修复 M-15)
secret 长度必须 ≥ JwtAuthenticator::MIN_SECRET_LEN(32 字节),
否则返回 AuthError::SecretTooShort。生产路径应使用本构造器。
Sourcepub fn with_password_verifier(
self,
verifier: Arc<dyn PasswordVerifier>,
) -> JwtAuthenticator
pub fn with_password_verifier( self, verifier: Arc<dyn PasswordVerifier>, ) -> JwtAuthenticator
配置密码验证器(v0.2.1 新增,修复 Critical S-1)
配置后,authenticate 会调用 verifier.verify_password 验证密码并获取 user_id。
生产环境必须调用此方法,否则 authenticate 不验证密码(Critical S-1)。
pub fn authenticate( &self, credentials: &Credentials, ) -> Result<Token, AuthError>
pub fn verify_token(&self, token: &str) -> Result<User, AuthError>
pub fn refresh_token(&self, refresh_token: &str) -> Result<Token, AuthError>
Auto Trait Implementations§
impl !RefUnwindSafe for JwtAuthenticator
impl !UnwindSafe for JwtAuthenticator
impl Freeze for JwtAuthenticator
impl Send for JwtAuthenticator
impl Sync for JwtAuthenticator
impl Unpin for JwtAuthenticator
impl UnsafeUnpin for JwtAuthenticator
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> 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 more