Skip to main content

OIDCClient

Struct OIDCClient 

Source
pub struct OIDCClient {
    pub config: OIDCProviderConfig,
    pub client_id: String,
    pub jwks_cache: Arc<JwksCache>,
    /* private fields */
}
Expand description

OIDC client for OpenID Connect flow.

Fields§

§config: OIDCProviderConfig

Provider configuration.

§client_id: String

Client ID.

§jwks_cache: Arc<JwksCache>

JWKS key cache for ID token signature verification.

Implementations§

Source§

impl OIDCClient

Source

pub fn new( config: OIDCProviderConfig, client_id: impl Into<String>, client_secret: impl Into<String>, ) -> Result<Self, JwksError>

Create new OIDC client with JWKS caching.

The JWKS cache TTL defaults to 1 hour.

§Errors

Returns JwksError if config.jwks_uri is not a valid HTTPS URL (HTTP is allowed only for localhost).

Source

pub fn with_jwks_cache( config: OIDCProviderConfig, client_id: impl Into<String>, client_secret: impl Into<String>, jwks_cache: Arc<JwksCache>, ) -> Self

Create OIDC client with a pre-built JWKS cache (for testing).

Source

pub fn authorization_url(&self, redirect_uri: &str) -> AuthorizationRequest

Generate an OIDC authorization URL with a fresh nonce for replay protection.

This extends the standard OAuth2 flow by appending a nonce parameter to the authorization URL. The returned AuthorizationRequest::nonce must be stored (e.g. in the encrypted session state) and passed to verify_id_token at callback time.

PKCE is always enabled for OIDC flows started via this method.

Source

pub async fn verify_id_token( &self, id_token: &str, expected_nonce: Option<&str>, max_age_secs: Option<u64>, ) -> Result<IdTokenClaims, String>

Verify an ID token’s JWT signature and claims.

Decodes the JWT header to extract the kid, fetches the matching public key from the JWKS cache, then validates signature, issuer, audience, and required claims.

Nonce: when expected_nonce is Some, the token’s nonce claim must match exactly. When it is None but the token contains a nonce claim, validation still succeeds — callers that generated the authorization URL via authorization_url MUST pass the stored nonce here.

max_age: when max_age_secs is Some, the token’s auth_time claim is required and must be within max_age_secs seconds of the current time. This prevents accepting tokens from sessions that were authenticated too long ago (RFC 6749 §3.1.2.1 / OIDC Core §3.1.2.1).

§Errors

Returns an error if the token is malformed, the signature is invalid, claims validation fails, the nonce doesn’t match, or the auth_time / max_age constraint is violated.

Source

pub async fn get_userinfo(&self, access_token: &str) -> Result<UserInfo, String>

Fetch user information from the provider’s userinfo endpoint.

§Errors

Returns an error if no userinfo endpoint is configured, the HTTP request fails, or the response cannot be parsed.

Trait Implementations§

Source§

impl Debug for OIDCClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,