jwt-lab 0.1.1

JWT crate for Rust: decode, verify, sign, mutate, JWK/JWKS, algorithm selection, time validation, and secure APIs.
Documentation
//! Quickstart example demonstrating JWT verification with algorithm validation
//!
//! This example shows how to decode and verify a JWT token with proper security
//! measures including algorithm validation to prevent algorithm confusion attacks.

use jwt_lab::{Jwt, Key, VerifyOptions, Algorithm};

fn main() -> anyhow::Result<()> {
    let token = std::env::args().nth(1).expect("token");
    let jwt = Jwt::decode(&token)?;

    // Always validate the algorithm to prevent alg confusion attacks
    jwt.verify(
        &Key::hs("supersecret"),
        VerifyOptions::default()
            .expect_alg(Algorithm::HS256)
            .leeway(30)
    )?;

    println!("Token is valid");
    Ok(())
}