Skip to main content

OAuthProvider

Trait OAuthProvider 

Source
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§

Source

fn name(&self) -> &str

Provider name, lowercase. Used as the URL path segment and the provider column in oauth_accounts.

Source

fn authorize_url( &self, redirect_uri: &str, state: &str, pkce_challenge: &str, ) -> String

Build the authorization URL the user should be redirected to.

Source

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.

Source

fn user_info<'a>( &'a self, access_token: &'a str, ) -> AuthFuture<'a, OAuthUserInfo>

Fetch user information from the provider using the access token.

Implementors§