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;
8use mockforge_openapi::OpenApiSpec;
9use std::collections::HashMap;
10use std::sync::Arc;
11use tokio::sync::RwLock;
12
13/// Cached OAuth2 introspection result
14#[derive(Debug, Clone)]
15pub struct CachedIntrospection {
16 /// The introspection result
17 pub result: AuthResult,
18 /// When this cache entry expires (Unix timestamp)
19 pub expires_at: i64,
20}
21
22/// Authentication middleware state
23#[derive(Clone)]
24pub struct AuthState {
25 /// Authentication configuration
26 pub config: AuthConfig,
27 /// Optional OpenAPI specification for route security validation
28 pub spec: Option<Arc<OpenApiSpec>>,
29 /// Optional OAuth2 client for token validation
30 pub oauth2_client: Option<oauth2::basic::BasicClient>,
31 /// Cache for OAuth2 token introspection results
32 pub introspection_cache: Arc<RwLock<HashMap<String, CachedIntrospection>>>,
33}