diff --git a/src/ic_backend/src/id_token.rs b/src/ic_backend/src/id_token.rs index b782c8e..6cec8d4 100644 --- a/src/ic_backend/src/id_token.rs +++ b/src/ic_backend/src/id_token.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{ state, - utils::{base64_decode, unix_timestamp}, + utils::{base64_decode, unix_timestamp, NANOS_IN_SECONDS}, }; /// The maximum age of an ID token (checked against the `iat` claim). @@ -24,7 +24,9 @@ pub type IdTokenResult = std::result::Result; pub struct JWTClaims { pub iss: String, pub aud: String, + /// Issued at (seconds since unix epoch) pub iat: u64, + /// Expires at (seconds since unix epoch) pub exp: u64, pub sub: String, pub nonce: String, @@ -32,7 +34,7 @@ pub struct JWTClaims { impl JWTClaims { pub fn expiration_timestamp_ns(&self) -> u64 { - self.exp * 1_000_000_000 + self.exp * NANOS_IN_SECONDS } pub fn validate(&self) -> Result<(), ValidationError> { diff --git a/src/ic_backend/src/utils.rs b/src/ic_backend/src/utils.rs index 6440d8a..ca9b890 100644 --- a/src/ic_backend/src/utils.rs +++ b/src/ic_backend/src/utils.rs @@ -6,9 +6,11 @@ use jsonwebtoken_rustcrypto::errors::ErrorKind; use crate::id_token::IdTokenResult; +pub const NANOS_IN_SECONDS: u64 = 1_000_000_000; + /// Returns the current unix timestamp in seconds pub fn unix_timestamp() -> u64 { - time() / 1_000_000_000 + time() / NANOS_IN_SECONDS } pub fn base64_decode(input: &str) -> IdTokenResult> {