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: OIDCProviderConfigProvider configuration.
client_id: StringClient ID.
jwks_cache: Arc<JwksCache>JWKS key cache for ID token signature verification.
Implementations§
Source§impl OIDCClient
impl OIDCClient
Sourcepub fn new(
config: OIDCProviderConfig,
client_id: impl Into<String>,
client_secret: impl Into<String>,
) -> Result<Self, JwksError>
pub fn new( config: OIDCProviderConfig, client_id: impl Into<String>, client_secret: impl Into<String>, ) -> Result<Self, JwksError>
Sourcepub fn with_jwks_cache(
config: OIDCProviderConfig,
client_id: impl Into<String>,
client_secret: impl Into<String>,
jwks_cache: Arc<JwksCache>,
) -> Self
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).
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.
Sourcepub async fn verify_id_token(
&self,
id_token: &str,
expected_nonce: Option<&str>,
max_age_secs: Option<u64>,
) -> Result<IdTokenClaims, String>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OIDCClient
impl !RefUnwindSafe for OIDCClient
impl Send for OIDCClient
impl Sync for OIDCClient
impl Unpin for OIDCClient
impl UnsafeUnpin for OIDCClient
impl !UnwindSafe for OIDCClient
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
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>
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>
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