Keats / jsonwebtoken

JWT lib in rust
MIT License
1.64k stars 260 forks source link

Example showing decoding without any kind of secret? #277

Closed brandonros closed 1 year ago

brandonros commented 1 year ago

I just want to be able to feed this library a JWT issued from a website and extract the expiration date, etc.

Since I am issued it by a website, I don't think I'd know the appropriate keys/secrets to validate its signature?

Keats commented 1 year ago

You have to create a dummy DecodingKey and use https://docs.rs/jsonwebtoken/latest/jsonwebtoken/struct.Validation.html#method.insecure_disable_signature_validation

Example i haven't run:

let key = DecodingKey::from_secret(&[]);
let mut validation = Validation::new(Algorithm::HS256);
validation.insecure_disable_signature_validation();

let data = decode<TypeYouWant>(&token, &key, &validation)?;
brandonros commented 1 year ago

Thank you!