use crate::{
cache::{Cache, MokaCacheImpl},
errors::Result,
http::{HttpClient, ReqwestHttpClient},
jwks::Jwks,
types::OidcProviderMetadata,
};
use std::sync::Arc;
#[cfg(all(not(target_arch = "wasm32"), feature = "http-reqwest", feature = "moka"))]
pub struct OidcClient {
pub http: Arc<ReqwestHttpClient>,
pub discovery_cache: Arc<MokaCacheImpl<String, OidcProviderMetadata>>,
pub jwks_cache: Arc<MokaCacheImpl<String, Jwks>>,
}
#[cfg(all(not(target_arch = "wasm32"), feature = "http-reqwest", feature = "moka"))]
impl OidcClient {
pub fn new() -> Result<Self> {
let http = Arc::new(ReqwestHttpClient::default());
let discovery_cache = Arc::new(MokaCacheImpl::new(100));
let jwks_cache = Arc::new(MokaCacheImpl::new(100));
Ok(Self { http, discovery_cache, jwks_cache })
}
pub fn http(&self) -> &dyn HttpClient {
self.http.as_ref()
}
pub fn discovery_cache(&self) -> &dyn Cache<String, OidcProviderMetadata> {
self.discovery_cache.as_ref()
}
pub fn jwks_cache(&self) -> &dyn Cache<String, Jwks> {
self.jwks_cache.as_ref()
}
}
#[cfg(all(not(target_arch = "wasm32"), feature = "http-reqwest", feature = "moka"))]
impl Default for OidcClient {
fn default() -> Self {
Self::new().expect("Failed to create default OIDC client")
}
}