pub struct Token { /* private fields */ }Expand description
A fully validated JWT token
This is the final result of the validation pipeline. By the time you receive
a Token, all validation steps have completed successfully:
- Parsing: Header and payload have been parsed from Base64URL-encoded segments
- Issuer validation: The
issclaim has been validated (or explicitly skipped for same-service tokens) - Signature verification: The cryptographic signature has been verified against the provided key
- Claims validation: Time-based claims (
exp,nbf,iat) have been validated, audience (aud) has been checked (if required), and any custom validation logic has been executed
The token is now fully trusted and safe to use. All claims can be accessed without additional validation checks.
§Example
ⓘ
use jwtiny::*;
let header = "eyJ...";
let token = ParsedToken::from_string(header)?;
let validated = TokenValidator::new(token)
.ensure_issuer(|iss| Ok(iss == "https://trusted.com"))
.verify_signature(SignatureVerification::with_secret_hs256(b"secret"))
.validate_token(ValidationConfig::default())
.run()?;
println!("Subject: {:?}", validated.subject());
println!("Issuer: {:?}", validated.issuer());Implementations§
Source§impl Token
impl Token
Sourcepub fn header(&self) -> &TokenHeader
pub fn header(&self) -> &TokenHeader
Get the token header
Sourcepub fn algorithm(&self) -> &AlgorithmId
pub fn algorithm(&self) -> &AlgorithmId
Get the algorithm
Sourcepub fn expiration(&self) -> Option<i64>
pub fn expiration(&self) -> Option<i64>
Get the expiration time (exp claim) as Unix timestamp
Sourcepub fn not_before(&self) -> Option<i64>
pub fn not_before(&self) -> Option<i64>
Get the not-before time (nbf claim) as Unix timestamp
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
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