Fix OAuth infinite redirect loop
Browse files- Ensure redirect_uri matches exactly between authorization and token exchange
- Use SPACE_HOST consistently in both requests on HF Spaces
- Fixes 400 Bad Request error during OAuth token exchange
- CHANGELOG.md +5 -0
- server.R +11 -5
CHANGELOG.md
CHANGED
|
@@ -50,6 +50,11 @@
|
|
| 50 |
- Added token aggregation from all sub-agents
|
| 51 |
|
| 52 |
### Fixed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
- **Supabase Client Debug Logging**
|
| 54 |
- Added debug output to show SUPABASE_URL and SUPABASE_KEY values during initialization
|
| 55 |
- Added environment variable diagnostic logging in server.R to check HF Spaces secrets
|
|
|
|
| 50 |
- Added token aggregation from all sub-agents
|
| 51 |
|
| 52 |
### Fixed
|
| 53 |
+
- **OAuth Redirect URI Mismatch**
|
| 54 |
+
- Fixed 400 Bad Request error during OAuth token exchange
|
| 55 |
+
- Ensured redirect_uri matches exactly between authorization and token exchange requests
|
| 56 |
+
- Both now use SPACE_HOST environment variable on HF Spaces
|
| 57 |
+
|
| 58 |
- **Supabase Client Debug Logging**
|
| 59 |
- Added debug output to show SUPABASE_URL and SUPABASE_KEY values during initialization
|
| 60 |
- Added environment variable diagnostic logging in server.R to check HF Spaces secrets
|
server.R
CHANGED
|
@@ -248,11 +248,17 @@ if 'agents.manager_agent' in sys.modules:
|
|
| 248 |
}
|
| 249 |
|
| 250 |
tryCatch({
|
| 251 |
-
# Get redirect URI
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
# Exchange code for token
|
| 258 |
token_result <- exchange_code_for_token(oauth_config, input$oauth_code, redirect_uri)
|
|
|
|
| 248 |
}
|
| 249 |
|
| 250 |
tryCatch({
|
| 251 |
+
# Get redirect URI - must match exactly what was used in authorization request
|
| 252 |
+
space_host <- Sys.getenv("SPACE_HOST", "")
|
| 253 |
+
if (space_host != "") {
|
| 254 |
+
redirect_uri <- paste0("https://", space_host)
|
| 255 |
+
} else {
|
| 256 |
+
redirect_uri <- paste0(session$clientData$url_protocol, "//",
|
| 257 |
+
session$clientData$url_hostname,
|
| 258 |
+
if (session$clientData$url_port != "") paste0(":", session$clientData$url_port) else "")
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
print(paste("OAuth: Token exchange using redirect_uri:", redirect_uri))
|
| 262 |
|
| 263 |
# Exchange code for token
|
| 264 |
token_result <- exchange_code_for_token(oauth_config, input$oauth_code, redirect_uri)
|