Skip to content

Base

base

OAuth provider base interface.

Defines the abstract interface for OAuth providers. All provider implementations (Google, GitHub, etc.) must inherit from OAuthProvider.

Classes

OAuthUserInfo dataclass

OAuthUserInfo(
    provider_user_id: str,
    email: str,
    email_verified: bool,
    name: str | None = None,
    avatar_url: str | None = None,
)

User information returned from OAuth provider.

OAuthTokens dataclass

OAuthTokens(
    access_token: str,
    refresh_token: str | None = None,
    expires_in: int | None = None,
    token_type: str = "Bearer",
)

Tokens returned from OAuth provider.

OAuthProvider

Bases: ABC

Abstract base class for OAuth providers.

Each provider (Google, GitHub, etc.) implements this interface.

Attributes
name abstractmethod property
name: str

Provider name (e.g., 'google', 'github').

authorization_endpoint abstractmethod property
authorization_endpoint: str

OAuth authorization URL.

token_endpoint abstractmethod property
token_endpoint: str

OAuth token exchange URL.

user_info_endpoint abstractmethod property
user_info_endpoint: str

User info API endpoint.

default_scopes abstractmethod property
default_scopes: str

Default OAuth scopes (space-separated).

Functions
exchange_code_for_tokens abstractmethod async
exchange_code_for_tokens(
    *, code: str, redirect_uri: str, code_verifier: str | None = None
) -> OAuthTokens

Exchange authorization code for access/refresh tokens.

Parameters:

Name Type Description Default
code str

Authorization code from callback

required
redirect_uri str

Redirect URI used in authorization

required
code_verifier str | None

Optional PKCE code verifier

None

Returns:

Type Description
OAuthTokens

OAuthTokens with access token and optional refresh token

Source code in fastauth/providers/base.py
@abstractmethod
async def exchange_code_for_tokens(
    self,
    *,
    code: str,
    redirect_uri: str,
    code_verifier: str | None = None,
) -> OAuthTokens:
    """
    Exchange authorization code for access/refresh tokens.

    Args:
        code: Authorization code from callback
        redirect_uri: Redirect URI used in authorization
        code_verifier: Optional PKCE code verifier

    Returns:
        OAuthTokens with access token and optional refresh token
    """
    ...
get_user_info abstractmethod async
get_user_info(*, access_token: str) -> OAuthUserInfo

Fetch user information using access token.

Parameters:

Name Type Description Default
access_token str

OAuth access token

required

Returns:

Type Description
OAuthUserInfo

OAuthUserInfo with user profile data

Source code in fastauth/providers/base.py
@abstractmethod
async def get_user_info(self, *, access_token: str) -> OAuthUserInfo:
    """
    Fetch user information using access token.

    Args:
        access_token: OAuth access token

    Returns:
        OAuthUserInfo with user profile data
    """
    ...
refresh_access_token abstractmethod async
refresh_access_token(*, refresh_token: str) -> OAuthTokens

Refresh access token using refresh token.

Parameters:

Name Type Description Default
refresh_token str

OAuth refresh token

required

Returns:

Type Description
OAuthTokens

OAuthTokens with new access token

Source code in fastauth/providers/base.py
@abstractmethod
async def refresh_access_token(self, *, refresh_token: str) -> OAuthTokens:
    """
    Refresh access token using refresh token.

    Args:
        refresh_token: OAuth refresh token

    Returns:
        OAuthTokens with new access token
    """
    ...