pub struct OAuth2Handler { /* private fields */ }Expand description
OAuth2 authentication handler.
Implementations§
Source§impl OAuth2Handler
impl OAuth2Handler
Sourcepub fn new(config: OAuth2Config) -> Result<Self>
pub fn new(config: OAuth2Config) -> Result<Self>
Create a new OAuth2 handler.
Generate an authorization URL for the OAuth2 flow.
Returns a tuple of (authorization_url, csrf_token, pkce_verifier). The user should be redirected to the authorization URL to approve access.
Sourcepub async fn exchange_code(
&self,
code: String,
pkce_verifier: String,
) -> Result<AccessToken>
pub async fn exchange_code( &self, code: String, pkce_verifier: String, ) -> Result<AccessToken>
Exchange an authorization code for an access token.
This should be called after the user approves access and is redirected back to your application with an authorization code.
§Arguments
code- The authorization code received from the OAuth2 callbackpkce_verifier- The PKCE verifier generated duringauthorize_url()
§Security
The PKCE verifier MUST be the same one generated by authorize_url().
This protects against authorization code interception attacks.
Sourcepub async fn refresh_token(&self, refresh_token: String) -> Result<AccessToken>
pub async fn refresh_token(&self, refresh_token: String) -> Result<AccessToken>
Refresh an access token using a refresh token.
§Arguments
refresh_token- The refresh token obtained during initial authorization
§Example
let handler = OAuth2Handler::new(config)?;
let refresh_token = "existing_refresh_token".to_string();
let new_token = handler.refresh_token(refresh_token).await?;Auto Trait Implementations§
impl Freeze for OAuth2Handler
impl RefUnwindSafe for OAuth2Handler
impl Send for OAuth2Handler
impl Sync for OAuth2Handler
impl Unpin 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