Skip to content

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiemontese committed Jan 15, 2024
1 parent 03b480e commit 68a002f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/auth0/cache/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Cache for InMemoryCache {
.transpose()
}

async fn put_jwks(&self, value_ref: &JsonWebKeySet, _expiration: Option<usize>) -> Result<(), Auth0Error> {
async fn put_jwks(&self, value_ref: &JsonWebKeySet, _expiration: Option<u64>) -> Result<(), Auth0Error> {
let key: String = cache::jwks_key(&self.caller, &self.audience);
let encrypted_value: Vec<u8> = crypto::encrypt(value_ref, self.encryption_key.as_str())?;
let _ = self.key_value.insert(key, encrypted_value);
Expand Down
2 changes: 1 addition & 1 deletion src/auth0/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait Cache: Send + Sync + std::fmt::Debug {

async fn get_jwks(&self) -> Result<Option<JsonWebKeySet>, Auth0Error>;

async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option<usize>) -> Result<(), Auth0Error>;
async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option<u64>) -> Result<(), Auth0Error>;
}

pub(in crate::auth0::cache) fn token_key(caller: &str, audience: &str) -> String {
Expand Down
6 changes: 3 additions & 3 deletions src/auth0/cache/redis_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = 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(())
}
Expand All @@ -63,11 +63,11 @@ impl Cache for RedisCache {
self.get(key).await
}

async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option<usize>) -> Result<(), Auth0Error> {
async fn put_jwks(&self, value_ref: &JsonWebKeySet, expiration: Option<u64>) -> 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<u8> = 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(())
}
Expand Down
7 changes: 5 additions & 2 deletions src/auth0/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68a002f

Please sign in to comment.