verifier
ModuleJWT verification: the signature checks and the verifier of registered claims.
Contents
use utopia_auth::jwt::verifier::Hs256;Rust
pub struct Hs256Checks HS256 signatures with a shared secret.
use utopia_auth::jwt::verifier::Rs256;Rust
pub struct Rs256Checks RS256 signatures with a PEM RSA public key.
use utopia_auth::jwt::verifier::Verifier;Rust
pub struct Verifier<S: SignatureCheck>Verifies a JWT: its signature, header and registered claims.
The expectations are fixed at construction: iss, acceptable aud
values and typ are checked when given; exp is required unless
allow_expired; nbf/iat are always checked; leeway tolerates skew.
Rust
use php_std::{Array, Value};
use utopia_auth::jwt::{Audience, Hs256, Jwt, Symmetric, Verifier};
let token = Jwt(Symmetric::new(b"secret", b"iss", None)?).issue(&Audience::One(b"app".to_vec()), 60, &Array::new(), 1_000)?;
let verifier = Verifier::new(Hs256::new(b"secret")?, Some(b"iss"), None, None, false, 0)?;
let claims = verifier.verify(token.as_bytes(), 1_030)?;
assert_eq!(claims.get_str("aud"), Some(&Value::from("app")));
let error = verifier.verify(token.as_bytes(), 2_000).unwrap_err();
assert_eq!(error.to_string(), "Token has expired");use utopia_auth::jwt::verifier::Audience;Rust
pub enum AudienceAn aud value: one recipient, or an array of them.
use utopia_auth::jwt::verifier::SignatureCheck;Rust
pub trait SignatureCheckHow a Verifier checks signatures: the JWS alg it expects and the
check itself. Implement it to verify another algorithm.