Implementation:ALwrity ALwrity OAuthTokenMonitoringService
| Knowledge Sources | |
|---|---|
| Domains | OAuth, Monitoring, Integration |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for monitoring per-platform OAuth token connection status across GSC, Bing, WordPress, Wix, YouTube, and LinkedIn, provided by the ALwrity OAuth subsystem.
Description
The OAuthTokenMonitoringService dispatches per-platform connection checks to determine whether a user has at least one valid (or refreshable) token for each integrated platform. Each checker (_check_gsc, _check_bing, _check_wordpress, _check_wix, _check_youtube, _check_linkedin) delegates to the platform-specific OAuth service and returns a boolean. The dispatch is wrapped by _safe_check so a single platform's failure does not abort the loop. The stable platform ordering (GSC, Bing, WordPress, Wix, YouTube, LinkedIn) is preserved for callers.
YouTube and LinkedIn checks use lazy imports so the module loads even when provider-specific keys are not configured, treating a construction failure as "not connected" rather than raising.
Usage
Import this service when:
- A dashboard needs to show which platforms a user has connected.
- A monitoring task must detect expired tokens that are still refreshable.
- A per-platform status check must be fault-tolerant (one failure does not abort the rest).
Code Reference
Source Location
- Repository: ALwrity
- File: backend/services/oauth_token_monitoring_service.py (L30-100+)
Signature
def _check_gsc(user_id: str) -> bool: ...
def _check_bing(user_id: str) -> bool: ...
def _check_wordpress(user_id: str) -> bool: ...
def _check_wix(user_id: str) -> bool: ...
def _check_youtube(user_id: str) -> bool: ...
def _check_linkedin(user_id: str) -> bool: ...
_PLATFORM_CHECKS: List[Tuple[str, Callable[[str], bool]]] = [
('gsc', _check_gsc),
('bing', _check_bing),
('wordpress', _check_wordpress),
('wix', _check_wix),
('youtube', _check_youtube),
('linkedin', _check_linkedin),
]
def _safe_check(platform: str, checker: Callable[[str], bool], user_id: str) -> bool:
"""Run a per-platform connection check, swallowing any exception."""
Import
from services.oauth_token_monitoring_service import _PLATFORM_CHECKS, _safe_check
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| user_id | str | Yes | Clerk user ID |
| platform | str | Yes (safe_check) | Platform name from _PLATFORM_CHECKS |
| checker | Callable[[str], bool] | Yes (safe_check) | Per-platform check function |
Outputs
| Name | Type | Description |
|---|---|---|
| _check_* | bool | True if user has at least one valid or refreshable token |
| _safe_check | bool | True if connected; False on failure or not connected |
Usage Examples
Checking all platforms for a user
from services.oauth_token_monitoring_service import _PLATFORM_CHECKS, _safe_check
user_id = "clerk_user_123"
statuses = {}
for platform, checker in _PLATFORM_CHECKS:
statuses[platform] = _safe_check(platform, checker, user_id)
print(statuses)
# {'gsc': True, 'bing': False, 'wordpress': True, 'wix': False, 'youtube': False, 'linkedin': True}