Skip to content

sok.config.oauth_providers

OAuth Providers - Authentication implementations for each service

To add a new provider:

  1. Create a class inheriting from BaseOAuthProvider
  2. Implement the authenticate() method
  3. Register the provider in OAUTH_PROVIDERS

BaseOAuthProvider

class BaseOAuthProvider(api_key: str, api_secret: str = '', port: int = 8765)

Bases: ABC

Base class for authentication providers

Initialize the OAuth provider.

Parameters

NameTypeDefaultDescription
api_keystrAPI key or client ID.
api_secretstr''API secret or client secret.
portint8765Local port for OAuth callback server.
Source

Attributes

Name
api_key
api_secret
callback_url
port

authenticateabstractmethod

def authenticate() -> Optional[Dict[str, Any]]:

Perform authentication and return session data.

Returns

  • Optional[Dict[str, Any]]Dict with session data (session_id, token, username, etc.)
  • Optional[Dict[str, Any]]None if authentication is cancelled
Source

IGDBOAuthProvider

class IGDBOAuthProvider

Bases: BaseOAuthProvider

IGDB/Twitch authentication provider

Source

authenticate

def authenticate() -> Optional[Dict[str, Any]]:

IGDB authentication via Twitch OAuth

Source

OAuthCallbackHandler

class OAuthCallbackHandler

Bases: BaseHTTPRequestHandler

Handles the OAuth callback

Source

Attributes

Name
callback_data

do_GET

def do_GET():

Receive the OAuth callback

Source

log_message

def log_message(format, *args):

Suppress HTTP server logging.

Parameters

NameTypeDescription
formatLog message format.
*argsFormat arguments.
Source

SpotifyOAuthProvider

class SpotifyOAuthProvider

Bases: BaseOAuthProvider

Spotify authentication provider

Source

authenticate

def authenticate() -> Optional[Dict[str, Any]]:

Spotify authentication via OAuth 2.0

Source

Functions

get_oauth_provider

def get_oauth_provider(
service_id: str,
api_key: str,
api_secret: str = '',
) -> Optional[BaseOAuthProvider]:

Get an OAuth provider instance for a service.

Parameters

NameTypeDefaultDescription
service_idstrService ID (tmdb, lastfm, etc.)
api_keystrService API key
api_secretstr''API secret if required

Returns

Source

Attributes

NameTypeValue
OAUTH_PROVIDERSDict[str, type]{SERVICE_SPOTIFY: SpotifyOAuthProvider, SERVICE_IGDB: IGDBOAuthProvider}
Built with Kiln