Skip to content

Commit

Permalink
Fix exp field for VAPID JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Dec 3, 2024
1 parent 64c1585 commit cf3b0ab
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/vapid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
collections::BTreeMap,
fmt::{Display, Formatter},
ops::Add,
time::{Duration, SystemTime, UNIX_EPOCH},
Expand All @@ -16,6 +15,7 @@ use openssl::{
nid::Nid,
pkey::{PKey, Private},
};
use rocket::serde::json;

use crate::config;

Expand Down Expand Up @@ -65,16 +65,16 @@ fn gen_vapid_header_with_key(origin: url::Origin, key: &SignerWithPubKey) -> Res
algorithm: AlgorithmType::Es256,
..Default::default()
};
let mut claims = BTreeMap::new();
claims.insert("aud", &origin_str);
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
// from_hours is still unstable https://github.com/rust-lang/rust/issues/120301
.add(Duration::from_secs(86400 /* 24h */))
.as_secs()
.to_string();
claims.insert("exp", &now);
.as_secs();
let claims = json::json!({
"aud": origin_str,
"exp": now
});
let token = Token::new(header, claims)
.sign_with_key(&key.signer)
.unwrap();
Expand Down

0 comments on commit cf3b0ab

Please sign in to comment.