1use crate::{
4 cache::{Cache, MokaCacheImpl},
5 errors::Result,
6 http::{HttpClient, ReqwestHttpClient},
7 jwks::Jwks,
8 types::OidcProviderMetadata,
9};
10use std::sync::Arc;
11
12#[cfg(all(not(target_arch = "wasm32"), feature = "http-reqwest", feature = "moka"))]
17pub struct OidcClient {
18 pub http: Arc<ReqwestHttpClient>,
20 pub discovery_cache: Arc<MokaCacheImpl<String, OidcProviderMetadata>>,
22 pub jwks_cache: Arc<MokaCacheImpl<String, Jwks>>,
24}
25
26#[cfg(all(not(target_arch = "wasm32"), feature = "http-reqwest", feature = "moka"))]
27impl OidcClient {
28 pub fn new() -> Result<Self> {
30 let http = Arc::new(ReqwestHttpClient::default());
31 let discovery_cache = Arc::new(MokaCacheImpl::new(100));
32 let jwks_cache = Arc::new(MokaCacheImpl::new(100));
33
34 Ok(Self { http, discovery_cache, jwks_cache })
35 }
36
37 pub fn http(&self) -> &dyn HttpClient {
39 self.http.as_ref()
40 }
41
42 pub fn discovery_cache(&self) -> &dyn Cache<String, OidcProviderMetadata> {
44 self.discovery_cache.as_ref()
45 }
46
47 pub fn jwks_cache(&self) -> &dyn Cache<String, Jwks> {
49 self.jwks_cache.as_ref()
50 }
51}
52
53#[cfg(all(not(target_arch = "wasm32"), feature = "http-reqwest", feature = "moka"))]
54impl Default for OidcClient {
55 fn default() -> Self {
56 Self::new().expect("Failed to create default OIDC client")
57 }
58}