pub struct ResourceServerClient {
pub http_client: Client,
pub jwks_cache: Arc<RwLock<HashMap<String, CachedJwks>>>,
pub discovery_cache: Arc<RwLock<HashMap<String, (OidcDiscoveryDocument, SystemTime)>>>,
pub discovery_cache_raw: Arc<RwLock<HashMap<String, CachedDiscoveryRaw>>>,
pub userinfo_cache: Arc<UserInfoCache>,
}Expand description
Resource server client for JWT validation
Fields§
§http_client: ClientHTTP client
jwks_cache: Arc<RwLock<HashMap<String, CachedJwks>>>JWKS cache
discovery_cache: Arc<RwLock<HashMap<String, (OidcDiscoveryDocument, SystemTime)>>>Discovery document cache (parsed)
discovery_cache_raw: Arc<RwLock<HashMap<String, CachedDiscoveryRaw>>>Discovery document cache (raw JSON for proxying)
userinfo_cache: Arc<UserInfoCache>Userinfo response cache (keyed by jti/sub, TTL = token remaining lifetime)
Implementations§
Source§impl ResourceServerClient
impl ResourceServerClient
Sourcepub async fn get_discovery_document(
&self,
issuer_url: &str,
) -> Result<OidcDiscoveryDocument>
pub async fn get_discovery_document( &self, issuer_url: &str, ) -> Result<OidcDiscoveryDocument>
Fetch OIDC discovery document with caching
Sourcepub async fn get_discovery_document_raw(
&self,
issuer_url: &str,
) -> Result<String>
pub async fn get_discovery_document_raw( &self, issuer_url: &str, ) -> Result<String>
Fetch OIDC discovery document as raw JSON with caching
Sourcepub async fn get_jwks(
&self,
jwks_uri: &str,
) -> Result<HashMap<String, (DecodingKey, Algorithm)>>
pub async fn get_jwks( &self, jwks_uri: &str, ) -> Result<HashMap<String, (DecodingKey, Algorithm)>>
Fetch JWKS with caching
Sourcepub async fn validate_jwt_with_options(
&self,
token: &str,
issuer_url: &str,
client_id: &str,
options: &JwtValidationOptions,
) -> Result<JwtClaims>
pub async fn validate_jwt_with_options( &self, token: &str, issuer_url: &str, client_id: &str, options: &JwtValidationOptions, ) -> Result<JwtClaims>
Validate JWT token with custom validation options
Sourcepub async fn validate_jwt(
&self,
token: &str,
issuer_url: &str,
client_id: &str,
) -> Result<JwtClaims>
pub async fn validate_jwt( &self, token: &str, issuer_url: &str, client_id: &str, ) -> Result<JwtClaims>
Validate JWT token with default options
Sourcepub async fn enrich_claims_with_userinfo(
&self,
claims: &mut JwtClaims,
token: &str,
issuer_url: &str,
userinfo_url_override: Option<&str>,
) -> Result<()>
pub async fn enrich_claims_with_userinfo( &self, claims: &mut JwtClaims, token: &str, issuer_url: &str, userinfo_url_override: Option<&str>, ) -> Result<()>
Adaptive claims enrichment: fill missing groups / role from the OIDC /userinfo endpoint.
IdP-agnostic design:
- If
claims.extraalready containsgroupsorrole, use them directly (zero cost). - Otherwise, call the
/userinfoendpoint with the access token as Bearer. - Merge
groupsandrolefrom userinfo intoclaims.extra. - Cache the userinfo response by
jti(orsubfallback) until the token expires.
This works with Kanidm (no groups in AT), Keycloak/Auth0 (groups in AT → fast path), Okta, Azure AD, Google, and any other OIDC-compliant provider.
§Arguments
claims- The JWT claims returned byvalidate_jwt_*. Mutated in place.token- The raw access token string (used as Bearer for the userinfo call).issuer_url- The OIDC issuer URL (used to derive the userinfo endpoint).userinfo_url_override- Optional explicit userinfo URL. IfNone, the URL is derived from the discovery document’suserinfo_endpoint, falling back to{issuer_url}/userinfo.
Trait Implementations§
Source§impl Clone for ResourceServerClient
impl Clone for ResourceServerClient
Source§fn clone(&self) -> ResourceServerClient
fn clone(&self) -> ResourceServerClient
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ResourceServerClient
impl !UnwindSafe for ResourceServerClient
impl Freeze for ResourceServerClient
impl Send for ResourceServerClient
impl Sync for ResourceServerClient
impl Unpin for ResourceServerClient
impl UnsafeUnpin for ResourceServerClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more