Spaces:
Running
Running
Commit
·
823f4d7
1
Parent(s):
c89d79e
Fix OAuth redirect URI for HF Spaces
Browse files- Convert SPACE_ID format for proper domain construction
- Use holistic-ai-agentgraph.hf.space format for redirect URIs
- Fix both login and callback redirect URI generation
- Ensure OAuth flow works correctly in HF Spaces environment
- backend/routers/auth.py +18 -0
backend/routers/auth.py
CHANGED
|
@@ -68,6 +68,16 @@ async def login(request: Request):
|
|
| 68 |
|
| 69 |
# Get the current host for redirect URI
|
| 70 |
base_url = str(request.base_url).rstrip('/')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
redirect_uri = f"{base_url}/auth/callback"
|
| 72 |
|
| 73 |
# Build authorization URL
|
|
@@ -102,6 +112,14 @@ async def oauth_callback(request: Request, code: str, state: str):
|
|
| 102 |
|
| 103 |
# Exchange code for tokens
|
| 104 |
base_url = str(request.base_url).rstrip('/')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
redirect_uri = f"{base_url}/auth/callback"
|
| 106 |
|
| 107 |
try:
|
|
|
|
| 68 |
|
| 69 |
# Get the current host for redirect URI
|
| 70 |
base_url = str(request.base_url).rstrip('/')
|
| 71 |
+
|
| 72 |
+
# Fix for HF Spaces domain format
|
| 73 |
+
if is_huggingface_space():
|
| 74 |
+
# HF Spaces uses holistic-ai-agentgraph.hf.space format
|
| 75 |
+
space_id = os.getenv("SPACE_ID", "")
|
| 76 |
+
if space_id:
|
| 77 |
+
# Convert "holistic-ai/AgentGraph" to "holistic-ai-agentgraph.hf.space"
|
| 78 |
+
space_domain = space_id.replace("/", "-").lower()
|
| 79 |
+
base_url = f"https://{space_domain}.hf.space"
|
| 80 |
+
|
| 81 |
redirect_uri = f"{base_url}/auth/callback"
|
| 82 |
|
| 83 |
# Build authorization URL
|
|
|
|
| 112 |
|
| 113 |
# Exchange code for tokens
|
| 114 |
base_url = str(request.base_url).rstrip('/')
|
| 115 |
+
|
| 116 |
+
# Fix for HF Spaces domain format
|
| 117 |
+
if is_huggingface_space():
|
| 118 |
+
space_id = os.getenv("SPACE_ID", "")
|
| 119 |
+
if space_id:
|
| 120 |
+
space_domain = space_id.replace("/", "-").lower()
|
| 121 |
+
base_url = f"https://{space_domain}.hf.space"
|
| 122 |
+
|
| 123 |
redirect_uri = f"{base_url}/auth/callback"
|
| 124 |
|
| 125 |
try:
|