pub struct OidcValidator { /* private fields */ }Expand description
OIDC token validator with JWKS caching.
Validates JWT tokens against an OIDC provider’s public keys. Automatically fetches and caches the JWKS for efficiency.
Implementations§
Source§impl OidcValidator
impl OidcValidator
Sourcepub async fn new(config: OidcConfig) -> Result<Self>
pub async fn new(config: OidcConfig) -> Result<Self>
Create a new OIDC validator.
This will perform OIDC discovery to find the JWKS URI
unless jwks_uri is explicitly set in config.
§Errors
Returns error if:
- Config validation fails
- OIDC discovery fails
- JWKS endpoint cannot be determined
Sourcepub fn with_jwks_uri(config: OidcConfig, jwks_uri: String) -> Self
pub fn with_jwks_uri(config: OidcConfig, jwks_uri: String) -> Self
Create a validator without performing discovery.
Use this for testing or when you have the JWKS URI directly.
Sourcepub async fn validate_token(&self, token: &str) -> Result<AuthenticatedUser>
pub async fn validate_token(&self, token: &str) -> Result<AuthenticatedUser>
Validate a JWT token and extract user information.
§Arguments
token- The JWT token string (without “Bearer “ prefix)
§Returns
AuthenticatedUser if token is valid, error otherwise.
§Errors
Returns error if:
- Token is malformed
- Signature verification fails
- Required claims are missing
- Token is expired
- Issuer/audience don’t match
Sourcepub fn is_required(&self) -> bool
pub fn is_required(&self) -> bool
Check if authentication is required.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the JWKS cache.
Call this if you need to force a refresh of the signing keys.
Auto Trait Implementations§
impl Freeze for OidcValidator
impl !RefUnwindSafe for OidcValidator
impl Send for OidcValidator
impl Sync for OidcValidator
impl Unpin for OidcValidator
impl UnsafeUnpin for OidcValidator
impl !UnwindSafe for OidcValidator
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