pub trait OAuthProvider: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn authorize_url(
&self,
redirect_uri: &str,
state: &str,
pkce_challenge: &str,
) -> String;
fn exchange_code<'a>(
&'a self,
code: &'a str,
redirect_uri: &'a str,
pkce_verifier: &'a str,
) -> AuthFuture<'a, String>;
fn user_info<'a>(
&'a self,
access_token: &'a str,
) -> AuthFuture<'a, OAuthUserInfo>;
}Expand description
Abstraction over an OAuth2 authorization code flow provider.
Each provider (Google, GitHub, etc.) implements this trait. The server
crate stores providers in a HashMap<String, Box<dyn OAuthProvider>>
keyed by provider name.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Provider name, lowercase. Used as the URL path segment and the
provider column in oauth_accounts.
Build the authorization URL the user should be redirected to.
Sourcefn exchange_code<'a>(
&'a self,
code: &'a str,
redirect_uri: &'a str,
pkce_verifier: &'a str,
) -> AuthFuture<'a, String>
fn exchange_code<'a>( &'a self, code: &'a str, redirect_uri: &'a str, pkce_verifier: &'a str, ) -> AuthFuture<'a, String>
Exchange an authorization code for an access token.
Sourcefn user_info<'a>(
&'a self,
access_token: &'a str,
) -> AuthFuture<'a, OAuthUserInfo>
fn user_info<'a>( &'a self, access_token: &'a str, ) -> AuthFuture<'a, OAuthUserInfo>
Fetch user information from the provider using the access token.