Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

Switch to BROKER_URL and remove public_return_url

Edwin Jose44025e9926cc
diff --git a/frontend/app/api/mutations/useConnectConnectorMutation.ts b/frontend/app/api/mutations/useConnectConnectorMutation.ts
index 8412f891e..e990a718f 100644
--- a/frontend/app/api/mutations/useConnectConnectorMutation.ts
+++ b/frontend/app/api/mutations/useConnectConnectorMutation.ts
@@ -5,7 +5,6 @@ import type { Connector } from "../queries/useGetConnectorsQuery";
interface ConnectResponse {
connection_id: string;
- public_return_url?: string;
oauth_config?: {
authorization_endpoint: string;
client_id: string;
@@ -70,7 +69,7 @@ export const useConnectConnectorMutation = () => {
localStorage.setItem("connecting_connector_type", connector.type);
localStorage.setItem("auth_purpose", "data_source");
- const returnUrl = result.public_return_url || window.location.origin;
+ const returnUrl = `${window.location.origin}/auth/callback`;
const stateQuery = `id=${result.connection_id}&return=${returnUrl}`;
const state = encodeBase64(stateQuery);
diff --git a/frontend/app/auth/callback/page.tsx b/frontend/app/auth/callback/page.tsx
index cff7e0e9f..9cb056b7c 100644
--- a/frontend/app/auth/callback/page.tsx
+++ b/frontend/app/auth/callback/page.tsx
@@ -41,6 +41,8 @@ function AuthCallbackContent() {
const state = searchParams.get("state");
const errorParam = searchParams.get("error");
+ console.log("OAuth callback state (raw):", state);
+
// Get stored auth info
const connectorId = localStorage.getItem("connecting_connector_id");
const storedConnectorType = localStorage.getItem(
@@ -89,6 +91,7 @@ function AuthCallbackContent() {
try {
// The entire state is now Base64 encoded: id=<connection_id>&return=<return_url>
const decodedState = decodeBase64(stateParam);
+ console.log("OAuth callback state (decoded):", decodedState);
const params = new URLSearchParams(decodedState);
if (params.has("id")) {
diff --git a/frontend/contexts/auth-context.tsx b/frontend/contexts/auth-context.tsx
index 9ee1391c9..bb9a0e41e 100644
--- a/frontend/contexts/auth-context.tsx
+++ b/frontend/contexts/auth-context.tsx
@@ -151,10 +151,12 @@ export function AuthProvider({ children }: AuthProviderProps) {
),
});
- const returnUrl = result.public_return_url || window.location.origin;
+ const returnUrl = `${window.location.origin}/auth/callback`;
const stateQuery = `id=${result.connection_id}&return=${returnUrl}`;
const state = encodeBase64(stateQuery);
+ console.log("OAuth state (encoded):", state, "decoded:", stateQuery);
+
const authUrl =
`${result.oauth_config.authorization_endpoint}?` +
`client_id=${result.oauth_config.client_id}&` +
diff --git a/src/config/settings.py b/src/config/settings.py
index fae7525cf..3e36867cc 100644
--- a/src/config/settings.py
+++ b/src/config/settings.py
@@ -110,8 +110,10 @@ WEBHOOK_BASE_URL = os.getenv(
"WEBHOOK_BASE_URL"
) # No default - must be explicitly configured
-# Public return URL for OAuth flows (Broker redirect)
-PUBLIC_RETURN_URL = os.getenv("PUBLIC_RETURN_URL")
+# OAuth callback broker URL -- when set, Google (and other providers) redirect
+# here instead of directly to the frontend. The broker then forwards to the
+# actual frontend origin that is carried in the OAuth state parameter.
+BROKER_URL = os.getenv("BROKER_URL")
# OpenSearch configuration
VECTOR_DIM = 1536
diff --git a/src/services/auth_service.py b/src/services/auth_service.py
index 8d4e6dd88..f8a14dda6 100644
--- a/src/services/auth_service.py
+++ b/src/services/auth_service.py
@@ -7,7 +7,7 @@ from datetime import datetime, timedelta
from typing import Optional
import asyncio
import os
-from config.settings import WEBHOOK_BASE_URL, is_no_auth_mode
+from config.settings import BROKER_URL, WEBHOOK_BASE_URL, is_no_auth_mode
from fastapi import HTTPException
logger = logging.getLogger(__name__)
@@ -88,11 +88,12 @@ class AuthService:
# Create connection configuration - use data/ directory for persistence
token_file = f"data/{connector_type}_{purpose}_{uuid.uuid4().hex[:8]}.json"
+ effective_redirect_uri = BROKER_URL or redirect_uri
config = {
"token_file": token_file,
"connector_type": connector_type,
"purpose": purpose,
- "redirect_uri": redirect_uri,
+ "redirect_uri": effective_redirect_uri,
}
# Only add webhook URL if WEBHOOK_BASE_URL is configured
@@ -165,11 +166,10 @@ class AuthService:
"oauth_config": {
"client_id": client_id,
"scopes": scopes,
- "redirect_uri": redirect_uri,
+ "redirect_uri": effective_redirect_uri,
"authorization_endpoint": auth_endpoint,
"token_endpoint": token_endpoint,
},
- "public_return_url": os.getenv("PUBLIC_RETURN_URL"),
}
async def _init_direct_connection(
@@ -233,6 +233,7 @@ class AuthService:
request=None,
) -> dict:
"""Handle OAuth callback - exchange authorization code for tokens"""
+ logger.info(f"OAuth callback state: {state}")
if not all([connection_id, authorization_code]):
raise ValueError(
"Missing required parameters (connection_id, authorization_code)"