Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn bench_decode(c: &mut Criterion) {
decode::<Claims>(
black_box(token),
black_box(&key),
black_box(&Validation::new(Algorithm::HS256)),
black_box(&Validation::new()),
)
})
});
Expand Down
7 changes: 4 additions & 3 deletions examples/auth0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};

let validation = {
let mut validation = Validation::new(header.alg);
validation.set_audience(&["https://dev-duzyayk4.eu.auth0.com/api/v2/"]);
validation.validate_exp = false;
let validation = Validation::new()
.with_exp(false, false)
.with_algorithm(header.alg)
.with_audience(&["https://dev-duzyayk4.eu.auth0.com/api/v2/"]);
validation
};

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() {
let token_data = match decode::<Claims>(
&token,
&DecodingKey::from_secret(key),
&Validation::new(Algorithm::HS512),
&Validation::new().with_algorithm(Algorithm::HS512),
) {
Ok(c) => c,
Err(err) => match *err.kind() {
Expand Down
8 changes: 4 additions & 4 deletions examples/custom_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod jwt_numeric_date {
let decoded = decode::<Claims>(
&token,
&DecodingKey::from_secret(SECRET.as_ref()),
&Validation::new(Algorithm::HS256),
&Validation::new().with_algorithm(Algorithm::HS256),
)
.expect("Failed to decode token");

Expand All @@ -103,7 +103,7 @@ mod jwt_numeric_date {
let decode_result = decode::<Claims>(
&overflow_token,
&DecodingKey::from_secret(SECRET.as_ref()),
&Validation::new(Algorithm::HS256),
&Validation::new().with_algorithm(Algorithm::HS256),
);

assert!(decode_result.is_err());
Expand All @@ -124,7 +124,7 @@ mod jwt_numeric_date {
let decoded = decode::<Claims>(
&token,
&DecodingKey::from_secret(SECRET.as_ref()),
&Validation::new(Algorithm::HS256),
&Validation::new().with_algorithm(Algorithm::HS256),
)
.expect("Failed to decode token")
.claims;
Expand Down Expand Up @@ -152,7 +152,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let token_data = jsonwebtoken::decode::<Claims>(
&token,
&DecodingKey::from_secret(SECRET.as_ref()),
&Validation::new(Algorithm::HS256),
&Validation::new().with_algorithm(Algorithm::HS256),
)?;

println!("token data:\n{:#?}", &token_data);
Expand Down
4 changes: 2 additions & 2 deletions examples/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
let token =
encode(&jsonwebtoken::Header::new(Algorithm::EdDSA), &claims, &encoding_key).unwrap();

let validation = Validation::new(Algorithm::EdDSA);
let validation = Validation::new().with_algorithm(Algorithm::EdDSA);
let _token_data = decode::<Claims>(&token, &decoding_key, &validation).unwrap();
}

Expand Down Expand Up @@ -69,7 +69,7 @@ mod tests {
encode(&jsonwebtoken::Header::new(Algorithm::EdDSA), &claims, &jot.encoding_key)
.unwrap();

let validation = Validation::new(Algorithm::EdDSA);
let validation = Validation::new().with_algorithm(Algorithm::EdDSA);
let token_data = decode::<Claims>(&token, &jot.decoding_key, &validation).unwrap();
assert_eq!(token_data.claims.sub, "test");
}
Expand Down
8 changes: 4 additions & 4 deletions examples/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fn main() {
Err(_) => panic!(), // in practice you would return the error
};

let mut validation = Validation::new(Algorithm::HS256);
validation.sub = Some("b@b.com".to_string());
validation.set_audience(&["me"]);
validation.set_required_spec_claims(&["exp", "sub", "aud"]);
let validation = Validation::new()
.with_algorithm(Algorithm::HS256)
.with_subject("b@b.com".to_string())
.with_audience(&["me"]);
let token_data = match decode::<Claims>(&token, &DecodingKey::from_secret(key), &validation) {
Ok(c) => c,
Err(err) => match *err.kind() {
Expand Down
2 changes: 1 addition & 1 deletion src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl TryFrom<&Jwk> for DecodingKey {
///
/// let token = "a.jwt.token".to_string();
/// // Claims is a struct that implements Deserialize
/// let token_message = decode::<Claims>(&token, &DecodingKey::from_secret("secret".as_ref()), &Validation::new(Algorithm::HS256));
/// let token_message = decode::<Claims>(&token, &DecodingKey::from_secret("secret".as_ref()), &Validation::new().with_algorithm(Algorithm::HS256));
/// ```
pub fn decode<T: DeserializeOwned>(
token: impl AsRef<[u8]>,
Expand Down
Loading