Skip to content

Commit 8399132

Browse files
committed
Update store
1 parent 8fe20a4 commit 8399132

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

atrium-oauth/oauth-client/src/oauth_client.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,25 @@ where
223223
}
224224
}
225225
pub async fn callback(&self, params: CallbackParams) -> Result<TokenSet> {
226-
let Some(state) = params.state else {
226+
let Some(state_key) = params.state else {
227227
return Err(Error::Callback("missing `state` parameter".into()));
228228
};
229229
let Some(state) = self
230230
.state_store
231-
.get(&state)
231+
.get(&state_key)
232232
.await
233233
.map_err(|e| Error::StateStore(Box::new(e)))?
234234
else {
235235
return Err(Error::Callback(format!(
236-
"unknown authorization state: {state}"
236+
"unknown authorization state: {state_key}"
237237
)));
238238
};
239+
// Prevent any kind of replay
240+
self.state_store
241+
.del(&state_key)
242+
.await
243+
.map_err(|e| Error::StateStore(Box::new(e)))?;
244+
239245
let metadata = self
240246
.resolver
241247
.get_authorization_server_metadata(&state.iss)

atrium-oauth/oauth-client/src/store.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use async_trait::async_trait;
55
use std::error::Error;
66
use std::hash::Hash;
77

8-
#[async_trait]
8+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
9+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
910
pub trait SimpleStore<K, V>
1011
where
1112
K: Eq + Hash,
@@ -14,7 +15,7 @@ where
1415
type Error: Error + Send + Sync + 'static;
1516

1617
async fn get(&self, key: &K) -> Result<Option<V>, Self::Error>;
17-
async fn set(&self, key: K, value: V) -> Result<Option<V>, Self::Error>;
18-
async fn del(&self, key: &K) -> Result<Option<V>, Self::Error>;
18+
async fn set(&self, key: K, value: V) -> Result<(), Self::Error>;
19+
async fn del(&self, key: &K) -> Result<(), Self::Error>;
1920
async fn clear(&self) -> Result<(), Self::Error>;
2021
}

atrium-oauth/oauth-client/src/store/memory.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ impl<K, V> Default for MemorySimpleStore<K, V> {
2323
}
2424
}
2525

26-
#[async_trait]
26+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
2728
impl<K, V> SimpleStore<K, V> for MemorySimpleStore<K, V>
2829
where
2930
K: Debug + Eq + Hash + Send + Sync + 'static,
@@ -34,11 +35,13 @@ where
3435
async fn get(&self, key: &K) -> Result<Option<V>, Self::Error> {
3536
Ok(self.store.lock().unwrap().get(key).cloned())
3637
}
37-
async fn set(&self, key: K, value: V) -> Result<Option<V>, Self::Error> {
38-
Ok(self.store.lock().unwrap().insert(key, value))
38+
async fn set(&self, key: K, value: V) -> Result<(), Self::Error> {
39+
self.store.lock().unwrap().insert(key, value);
40+
Ok(())
3941
}
40-
async fn del(&self, key: &K) -> Result<Option<V>, Self::Error> {
41-
Ok(self.store.lock().unwrap().remove(key))
42+
async fn del(&self, key: &K) -> Result<(), Self::Error> {
43+
self.store.lock().unwrap().remove(key);
44+
Ok(())
4245
}
4346
async fn clear(&self) -> Result<(), Self::Error> {
4447
self.store.lock().unwrap().clear();

0 commit comments

Comments
 (0)