Skip to content

Commit

Permalink
fix key formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Oct 29, 2023
1 parent 331699d commit e72f33b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/kitsune-oidc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct OidcService {
}

impl OidcService {
#[inline]
pub async fn initialise(config: &OidcConfiguration, redirect_uri: String) -> Result<Self> {
let provider_metadata = CoreProviderMetadata::discover_async(
IssuerUrl::new(config.server_url.to_string())?,
Expand Down
11 changes: 7 additions & 4 deletions crates/kitsune-oidc/src/state/store/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ impl Redis {
pub fn new(pool: deadpool_redis::Pool) -> Self {
Self { pool }
}

#[inline]
fn format_key(key: &str) -> String {
format!("{REDIS_PREFIX}:{key}")
}
}

#[async_trait]
impl Store for Redis {
async fn get_and_remove(&self, key: &str) -> Result<LoginState> {
let mut conn = self.pool.get().await?;
let raw_value: String = conn.get_del(key).await?;
let raw_value: String = conn.get_del(Self::format_key(key)).await?;

let mut raw_value = raw_value.into_bytes();
Ok(simd_json::from_slice(&mut raw_value)?)
}

async fn set(&self, key: &str, value: LoginState) -> Result<()> {
let key = format!("{REDIS_PREFIX}:{key}");

let raw_value = simd_json::to_string(&value)?;
let mut conn = self.pool.get().await?;
conn.set(key, raw_value).await?;
conn.set(Self::format_key(key), raw_value).await?;

Ok(())
}
Expand Down

0 comments on commit e72f33b

Please sign in to comment.