pub struct OAuth2Handler { /* private fields */ }Expand description
OAuth2/OIDC authentication handler
Implementations§
Source§impl OAuth2Handler
impl OAuth2Handler
Sourcepub async fn from_discovery(
settings: &OAuth2Settings,
redirect_url: &str,
) -> Result<Self, OAuth2Error>
pub async fn from_discovery( settings: &OAuth2Settings, redirect_url: &str, ) -> Result<Self, OAuth2Error>
Create a new OAuth2Handler using OIDC discovery
This performs automatic discovery of the OIDC provider’s configuration using the well-known endpoint.
Sourcepub fn generate_auth_url(&self) -> AuthRequest
pub fn generate_auth_url(&self) -> AuthRequest
Generate an authorization URL for the OAuth2 flow
Returns an AuthRequest containing the URL to redirect the user to,
along with the state, PKCE verifier, and nonce that must be stored
for later verification.
Sourcepub async fn exchange_and_validate(
&self,
code: &str,
pkce_verifier: &str,
nonce: &str,
) -> Result<TokenResult, OAuth2Error>
pub async fn exchange_and_validate( &self, code: &str, pkce_verifier: &str, nonce: &str, ) -> Result<TokenResult, OAuth2Error>
Sourcepub fn extract_user_info(&self, result: &TokenResult) -> UserInfo
pub fn extract_user_info(&self, result: &TokenResult) -> UserInfo
Extract user information from ID token claims
This extracts the subject, email, preferred_username, and group membership
based on the OAuth2 settings configuration.
Sourcepub fn generate_username(user_info: &UserInfo) -> String
pub fn generate_username(user_info: &UserInfo) -> String
Generate a unique username for auto-provisioning
Priority:
preferred_usernameclaim- Local part of email (before @)
- Subject claim
Sourcepub fn issuer_url(&self) -> &str
pub fn issuer_url(&self) -> &str
Get the issuer URL string
Sourcepub fn settings(&self) -> &OAuth2Settings
pub fn settings(&self) -> &OAuth2Settings
Get a reference to the settings
Auto Trait Implementations§
impl Freeze for OAuth2Handler
impl !RefUnwindSafe for OAuth2Handler
impl Send for OAuth2Handler
impl Sync for OAuth2Handler
impl Unpin for OAuth2Handler
impl UnsafeUnpin for OAuth2Handler
impl !UnwindSafe for OAuth2Handler
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
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