From 68a002fe5aac12bd7192ae5a0f7748b33eb9c0ec Mon Sep 17 00:00:00 2001 From: Cristiano Piemontese Date: Mon, 15 Jan 2024 15:06:40 +0100 Subject: [PATCH] upgrade --- src/auth0/cache/inmemory.rs | 2 +- src/auth0/cache/mod.rs | 2 +- src/auth0/cache/redis_impl.rs | 6 +++--- src/auth0/token.rs | 7 +++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/auth0/cache/inmemory.rs b/src/auth0/cache/inmemory.rs index f4d296a..43244e6 100644 --- a/src/auth0/cache/inmemory.rs +++ b/src/auth0/cache/inmemory.rs @@ -48,7 +48,7 @@ impl Cache for InMemoryCache { .transpose() } - async fn put_jwks(&self, value_ref: &JsonWebKeySet, _expiration: Option) -> Result<(), Auth0Error> { + async fn put_jwks(&self, value_ref: &JsonWebKeySet, _expiration: Option) -> Result<(), Auth0Error> { let key: String = cache::jwks_key(&self.caller, &self.audience); let encrypted_value: Vec = crypto::encrypt(value_ref, self.encryption_key.as_str())?; let _ = self.key_value.insert(key, encrypted_value); diff --git a/src/auth0/cache/mod.rs b/src/auth0/cache/mod.rs index af7c8bf..c7502bf 100644 --- a/src/auth0/cache/mod.rs +++ b/src/auth0/cache/mod.rs @@ -20,7 +20,7 @@ pub trait Cache: Send + Sync + std::fmt::Debug { async fn get_jwks(&self) -> Result, Auth0Error>; - async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option) -> Result<(), Auth0Error>; + async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option) -> Result<(), Auth0Error>; } pub(in crate::auth0::cache) fn token_key(caller: &str, audience: &str) -> String { diff --git a/src/auth0/cache/redis_impl.rs b/src/auth0/cache/redis_impl.rs index 629ca24..07d21d1 100644 --- a/src/auth0/cache/redis_impl.rs +++ b/src/auth0/cache/redis_impl.rs @@ -53,7 +53,7 @@ impl Cache for RedisCache { let key: &str = &cache::token_key(&self.caller, &self.audience); let mut connection = self.client.get_async_connection().await?; let encrypted_value: Vec = crypto::encrypt(value_ref, self.encryption_key.as_str())?; - let expiration: usize = value_ref.lifetime_in_seconds(); + let expiration: u64 = value_ref.lifetime_in_seconds(); connection.set_ex(key, encrypted_value, expiration).await?; Ok(()) } @@ -63,11 +63,11 @@ impl Cache for RedisCache { self.get(key).await } - async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option) -> Result<(), Auth0Error> { + async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option) -> Result<(), Auth0Error> { let key: &str = &cache::jwks_key(&self.caller, &self.audience); let mut connection = self.client.get_async_connection().await?; let encrypted_value: Vec = crypto::encrypt(value_ref, self.encryption_key.as_str())?; - let expiration: usize = expiration.unwrap_or(86400); + let expiration: u64 = expiration.unwrap_or(86400); connection.set_ex(key, encrypted_value, expiration).await?; Ok(()) } diff --git a/src/auth0/token.rs b/src/auth0/token.rs index f2b663c..6b35d81 100644 --- a/src/auth0/token.rs +++ b/src/auth0/token.rs @@ -88,8 +88,11 @@ impl Token { } } - pub fn lifetime_in_seconds(&self) -> usize { - (self.expire_date - self.issue_date).num_seconds() as usize + pub fn lifetime_in_seconds(&self) -> u64 { + (self.expire_date - self.issue_date) + .to_std() + .expect("expire_date should be greater than issue_date") + .as_secs() } // Check if the token remaining lifetime it's less than a randomized percentage that is between