|
Cat Feeder
1.0.0
The Cat feeder project
|
This document describes the OAuthAuthentication helper used by the backend to manage OAuth provider configuration, authorization flows and token exchange.
Location
backend/src/libs/utils/oauth_authentication.pyOverview
OAuthAuthentication class centralises OAuth provider lifecycle: adding providers, generating authorization URLs, exchanging authorization codes for tokens, fetching user information and registering active OAuth connections for users.TAB_USER_OAUTH_CONNECTION, TAB_VERIFICATION, TAB_ACTIVE_OAUTHS, TAB_ACCOUNTS) to persist provider configuration and active connections.Key responsibilities
user_info endpoints.Important configuration
CONST.REDIRECT_URI (used when generating authorization URLs and exchanging codes).TAB_USER_OAUTH_CONNECTION database table. Provider rows are expected to include fields such as client_id, client_secret, authorisation_base_url, token_grabber_base_url, and user_info_base_url.Class: OAuthAuthentication
Constructor
RuntimeManager (database, boilerplates, headers).Primary public endpoints / methods
async oauth_login(request: Request) -> Responseprovider.authorization_url on success.async oauth_callback(request: Request) -> Responsecode and state).code for tokens.async add_oauth_provider(request: Request, provider: str)TAB_USER_OAUTH_CONNECTION.client_id, client_secret, provider_scope, authorisation_base_url, token_grabber_base_url, user_info_base_url.async update_oauth_provider_data(request: Request, provider: str)async patch_oauth_provider_data(request: Request, provider: str)async delete_oauth_provider(request: Request, provider: str)refresh_token(provider_name: str, refresh_link: str) -> Union[str, None]Internal helpers (high-level)
_generate_oauth_authorization_url(provider: str) -> Union[int,str]state token and stores verification entry in TAB_VERIFICATION with an expiration._exchange_code_for_token(provider: str, code: str)token_grabber_base_url to exchange code for tokens. Returns parsed token response or an error response._get_user_info(provider: str, access_token: str)user_info_base_url with Authorization: Bearer <token> to retrieve user profile/email._oauth_user_logger(user_info: Dict, provider: str, connection_data: list) -> ResponseTAB_ACTIVE_OAUTHS, and issues an application token via BoilerplateIncoming.log_user_in()._handle_token_response(token_response: Dict, provider: str) -> Response_exchange_code_for_token, extracts expiry/refresh token and delegates to _oauth_user_logger.Expected database interactions (high level)
TAB_USER_OAUTH_CONNECTION stores provider configuration.TAB_VERIFICATION stores temporary state values used to protect callback flows.TAB_ACCOUNTS stores user accounts; TAB_ACTIVE_OAUTHS stores active oauth connections linking service_id and user_id.Example endpoints (registered by EndpointManager/PathManager)
POST /api/v1/oauth/login — body {"provider": "google"} — returns an authorization_url for the client to follow.GET /api/v1/oauth/callback — provider callback (query: code, state).POST /api/v1/oauth/{provider} — add oauth provider (admin).Security and notes
References
backend/src/libs/utils/oauth_authentication.pymanual_documentation/endpoint_manager/endpoint_manager.md for how OAuth endpoints are registered.TODO
CLIENT_ID/CLIENT_SECRET environment guidance (do not commit secrets).Overview
OAuthAuthentication class centralises OAuth provider lifecycle: adding providers, generating authorization URLs, exchanging authorization codes for tokens, fetching user information and registering active OAuth connections for users.TAB_USER_OAUTH_CONNECTION, TAB_VERIFICATION, TAB_ACTIVE_OAUTHS, TAB_ACCOUNTS) to persist provider configuration and active connections.Key responsibilities
user_info endpoints.Important configuration
CONST.REDIRECT_URI (used when generating authorization URLs and exchanging codes).TAB_USER_OAUTH_CONNECTION database table. Provider rows are expected to include fields such as client_id, client_secret, authorisation_base_url, token_grabber_base_url, and user_info_base_url.Class: OAuthAuthentication
Constructor
RuntimeManager (database, boilerplates, headers).Primary public endpoints / methods
async oauth_login(request: Request) -> Responseprovider.authorization_url on success.async oauth_callback(request: Request) -> Responsecode and state).code for tokens.async add_oauth_provider(request: Request, provider: str)TAB_USER_OAUTH_CONNECTION.client_id, client_secret, provider_scope, authorisation_base_url, token_grabber_base_url, user_info_base_url.async update_oauth_provider_data(request: Request, provider: str)async patch_oauth_provider_data(request: Request, provider: str)async delete_oauth_provider(request: Request, provider: str)refresh_token(provider_name: str, refresh_link: str) -> Union[str, None]Internal helpers (high-level)
_generate_oauth_authorization_url(provider: str) -> Union[int,str]state token and stores verification entry in TAB_VERIFICATION with an expiration._exchange_code_for_token(provider: str, code: str)token_grabber_base_url to exchange code for tokens. Returns parsed token response or an error response._get_user_info(provider: str, access_token: str)user_info_base_url with Authorization: Bearer <token> to retrieve user profile/email._oauth_user_logger(user_info: Dict, provider: str, connection_data: list) -> ResponseTAB_ACTIVE_OAUTHS, and issues an application token via BoilerplateIncoming.log_user_in()._handle_token_response(token_response: Dict, provider: str) -> Response_exchange_code_for_token, extracts expiry/refresh token and delegates to _oauth_user_logger.Expected database interactions (high level)
TAB_USER_OAUTH_CONNECTION stores provider configuration.TAB_VERIFICATION stores temporary state values used to protect callback flows.TAB_ACCOUNTS stores user accounts; TAB_ACTIVE_OAUTHS stores active oauth connections linking service_id and user_id.Example endpoints (registered by EndpointManager/PathManager)
POST /api/v1/oauth/login — body {"provider": "google"} — returns an authorization_url for the client to follow.GET /api/v1/oauth/callback — provider callback (query: code, state).POST /api/v1/oauth/{provider} — add oauth provider (admin).Security and notes
References
backend/src/libs/utils/oauth_authentication.pymanual_documentation/endpoint_manager/endpoint_manager.md for how OAuth endpoints are registered.TODO
CLIENT_ID/CLIENT_SECRET environment guidance (do not commit secrets).