sok.config.oauth_providers
OAuth Providers - Authentication implementations for each service
To add a new provider:
- Create a class inheriting from BaseOAuthProvider
- Implement the authenticate() method
- 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
| Name | Type | Default | Description |
|---|---|---|---|
api_key | str | API key or client ID. | |
api_secret | str | '' | API secret or client secret. |
port | int | 8765 | Local port for OAuth callback server. |
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
IGDBOAuthProvider
class IGDBOAuthProviderBases: BaseOAuthProvider
IGDB/Twitch authentication provider
Sourceauthenticate
def authenticate() -> Optional[Dict[str, Any]]:IGDB authentication via Twitch OAuth
SourceOAuthCallbackHandler
class OAuthCallbackHandlerBases: BaseHTTPRequestHandler
Handles the OAuth callback
SourceAttributes
| Name |
|---|
callback_data |
do_GET
def do_GET():Receive the OAuth callback
Sourcelog_message
def log_message(format, *args):Suppress HTTP server logging.
Parameters
| Name | Type | Description |
|---|---|---|
format | Log message format. | |
*args | Format arguments. |
SpotifyOAuthProvider
class SpotifyOAuthProviderBases: BaseOAuthProvider
Spotify authentication provider
Sourceauthenticate
def authenticate() -> Optional[Dict[str, Any]]:Spotify authentication via OAuth 2.0
SourceFunctions
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
| Name | Type | Default | Description |
|---|---|---|---|
service_id | str | Service ID (tmdb, lastfm, etc.) | |
api_key | str | Service API key | |
api_secret | str | '' | API secret if required |
Returns
Optional[BaseOAuthProvider]Provider instance or None if not found
Attributes
| Name | Type | Value |
|---|---|---|
OAUTH_PROVIDERS | Dict[str, type] | {SERVICE_SPOTIFY: SpotifyOAuthProvider, SERVICE_IGDB: IGDBOAuthProvider} |