mockforge_http/auth/
state.rs

1//! Authentication state management
2//!
3//! This module handles the authentication state containing configuration
4//! and runtime data needed for authentication operations.
5
6use super::types::AuthResult;
7use mockforge_core::{config::AuthConfig, OpenApiSpec};
8use std::collections::HashMap;
9use std::sync::Arc;
10use tokio::sync::RwLock;
11
12/// Cached OAuth2 introspection result
13#[derive(Debug, Clone)]
14pub struct CachedIntrospection {
15    /// The introspection result
16    pub result: AuthResult,
17    /// When this cache entry expires (Unix timestamp)
18    pub expires_at: i64,
19}
20
21/// Authentication middleware state
22#[derive(Clone)]
23pub struct AuthState {
24    pub config: AuthConfig,
25    pub spec: Option<Arc<OpenApiSpec>>,
26    pub oauth2_client: Option<oauth2::basic::BasicClient>,
27    /// Cache for OAuth2 token introspection results
28    pub introspection_cache: Arc<RwLock<HashMap<String, CachedIntrospection>>>,
29}