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 /// Authentication configuration
25 pub config: AuthConfig,
26 /// Optional OpenAPI specification for route security validation
27 pub spec: Option<Arc<OpenApiSpec>>,
28 /// Optional OAuth2 client for token validation
29 pub oauth2_client: Option<oauth2::basic::BasicClient>,
30 /// Cache for OAuth2 token introspection results
31 pub introspection_cache: Arc<RwLock<HashMap<String, CachedIntrospection>>>,
32}