diff --git a/modules/auth/oauthConnectTicket.py b/modules/auth/oauthConnectTicket.py index f54187cb..55e0944d 100644 --- a/modules/auth/oauthConnectTicket.py +++ b/modules/auth/oauthConnectTicket.py @@ -29,6 +29,25 @@ _msg = apiRouteContext("oauthConnectTicket") _CONNECT_TICKET_TTL_SEC = 600 +# OAuth providers sometimes redirect to the API root if the app redirect URL omits the path. +OAUTH_FLOW_CALLBACK_PATHS: Dict[str, str] = { + "clickup_connect": "/api/clickup/auth/connect/callback", + "msft_connect": "/api/msft/auth/connect/callback", + "google_connect": "/api/google/auth/connect/callback", +} + + +def oauth_callback_redirect_path(state: str) -> str | None: + """Map connect-ticket JWT (OAuth ``state`` param) to the correct callback route.""" + try: + data = jose_jwt.decode(state, SECRET_KEY, algorithms=[ALGORITHM]) + except JWTError: + return None + flow = data.get("flow") + if not isinstance(flow, str): + return None + return OAUTH_FLOW_CALLBACK_PATHS.get(flow) + def issue_connect_ticket(flow: str, connection_id: str, user_id: str) -> str: """Issue a short-lived JWT for starting a data-connection OAuth popup."""