Skip to main content

securitydept_oidc_client/pending_store/
base.rs

1use serde::Deserialize;
2
3use crate::OidcResult;
4
5/// Stored values for a pending OAuth flow (nonce + optional PKCE
6/// code_verifier).
7#[derive(Clone)]
8pub struct PendingOauth {
9    pub nonce: String,
10    pub code_verifier: Option<String>,
11    pub extra_data: Option<serde_json::Value>,
12}
13
14pub trait PendingOauthStoreConfig:
15    Sized + for<'de> Deserialize<'de> + Clone + Default + Send + Sync
16{
17}
18
19pub trait PendingOauthStore: Sized + Send + Sync {
20    type Config: PendingOauthStoreConfig;
21
22    fn from_config(config: &Self::Config) -> Self;
23    fn from_config_opt(config_opt: Option<&Self::Config>) -> Self {
24        if let Some(config) = config_opt {
25            Self::from_config(config)
26        } else {
27            Self::from_config(&Self::Config::default())
28        }
29    }
30    /// Store nonce and optional PKCE code_verifier for the given state (CSRF
31    /// token).
32    fn insert(
33        &self,
34        state: String,
35        nonce: String,
36        code_verifier: Option<String>,
37        extra_data: Option<serde_json::Value>,
38    ) -> impl Future<Output = OidcResult<()>> + Send;
39    /// Take the pending data for this state (one-time use). Returns None if
40    /// state unknown or already used.
41    fn take(&self, state: &str) -> impl Future<Output = OidcResult<Option<PendingOauth>>> + Send;
42}