pub struct JwtConfig {
pub algorithm: JwtAlgorithm,
pub issuer: Option<String>,
pub audience: Option<String>,
pub leeway_seconds: u64,
pub validate_exp: bool,
pub validate_nbf: bool,
}Available on crate features
auth and auth-jwt only.Expand description
Configuration for JWT validation.
Fields§
§algorithm: JwtAlgorithmAlgorithm and key for validation.
issuer: Option<String>Expected issuer (iss claim).
audience: Option<String>Expected audience (aud claim).
leeway_seconds: u64Leeway in seconds for expiration checks.
validate_exp: boolWhether to validate expiration.
validate_nbf: boolWhether to validate not-before.
Implementations§
Source§impl JwtConfig
impl JwtConfig
Sourcepub fn hs256(secret: impl Into<String>) -> Self
pub fn hs256(secret: impl Into<String>) -> Self
Create a new config with HS256 algorithm.
§Example
use allframe_core::auth::JwtConfig;
let config = JwtConfig::hs256("my-secret-key");Sourcepub fn rs384(public_key_pem: impl Into<String>) -> Self
pub fn rs384(public_key_pem: impl Into<String>) -> Self
Create a new config with RS384 algorithm.
Sourcepub fn rs512(public_key_pem: impl Into<String>) -> Self
pub fn rs512(public_key_pem: impl Into<String>) -> Self
Create a new config with RS512 algorithm.
Sourcepub fn eddsa(public_key_pem: impl Into<String>) -> Self
pub fn eddsa(public_key_pem: impl Into<String>) -> Self
Create a new config with EdDSA algorithm.
Sourcepub fn from_env() -> Option<Self>
pub fn from_env() -> Option<Self>
Create config from environment variables.
Reads:
JWT_SECRET- HMAC secret (for HS256)JWT_PUBLIC_KEY- RSA public key (for RS256, overrides JWT_SECRET)JWT_ISSUER- Expected issuerJWT_AUDIENCE- Expected audienceJWT_LEEWAY- Leeway in seconds (default: 60)
Sourcepub fn with_issuer(self, issuer: impl Into<String>) -> Self
pub fn with_issuer(self, issuer: impl Into<String>) -> Self
Set the expected issuer.
Sourcepub fn with_audience(self, audience: impl Into<String>) -> Self
pub fn with_audience(self, audience: impl Into<String>) -> Self
Set the expected audience.
Sourcepub fn with_leeway(self, seconds: u64) -> Self
pub fn with_leeway(self, seconds: u64) -> Self
Set the leeway for expiration checks (in seconds).
Sourcepub fn without_exp_validation(self) -> Self
pub fn without_exp_validation(self) -> Self
Disable expiration validation.
Sourcepub fn without_nbf_validation(self) -> Self
pub fn without_nbf_validation(self) -> Self
Disable not-before validation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JwtConfig
impl RefUnwindSafe for JwtConfig
impl Send for JwtConfig
impl Sync for JwtConfig
impl Unpin for JwtConfig
impl UnwindSafe for JwtConfig
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)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::RequestSource§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