Token

Struct Token 

Source
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 iss claim 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

Source

pub fn header(&self) -> &TokenHeader

Get the token header

Source

pub fn algorithm(&self) -> &AlgorithmId

Get the algorithm

Source

pub fn claims(&self) -> &Claims

Get all claims

Source

pub fn issuer(&self) -> Option<&str>

Get the issuer (iss claim)

Source

pub fn subject(&self) -> Option<&str>

Get the subject (sub claim)

Source

pub fn audience(&self) -> Option<&str>

Get the audience (aud claim)

Source

pub fn expiration(&self) -> Option<i64>

Get the expiration time (exp claim) as Unix timestamp

Source

pub fn not_before(&self) -> Option<i64>

Get the not-before time (nbf claim) as Unix timestamp

Source

pub fn issued_at(&self) -> Option<i64>

Get the issued-at time (iat claim) as Unix timestamp

Source

pub fn jwt_id(&self) -> Option<&str>

Get the JWT ID (jti claim)

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.