Skip to content

Commit

Permalink
fix: properly set iat inside Ear::new()
Browse files Browse the repository at this point in the history
Set iat (issued at) claim to the current time when creating a new token.

Also, fix a minor typo in comment.

Signed-off-by: Sergei Trofimov <[email protected]>
  • Loading branch information
setrofim committed Oct 31, 2024
1 parent b533cbb commit b8fadff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use core::ops::DerefMut;

use std::collections::BTreeMap;
use std::fmt;
use std::time::{SystemTime, UNIX_EPOCH};

use jsonwebtoken::{self as jwt, jwk};
use openssl::{bn, ec, nid::Nid, pkey};
Expand Down Expand Up @@ -62,7 +63,10 @@ impl Ear {
pub fn new() -> Ear {
Ear {
profile: "".to_string(),
iat: 0,
iat: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as i64,
vid: VerifierID::new(),
submods: BTreeMap::new(),
nonce: None,
Expand Down Expand Up @@ -119,7 +123,7 @@ impl Ear {
key: &jwt::DecodingKey,
) -> Result<Self, Error> {
let mut validation = jwt::Validation::new(alg);
// the default validation sets "exp" as a mandatory claim, which an E is not required to
// the default validation sets "exp" as a mandatory claim, which an EAR is not required to
// have.
validation.set_required_spec_claims::<&str>(&[]);

Expand Down

0 comments on commit b8fadff

Please sign in to comment.