Spaces:
Running
Running
Commit
Β·
f8eaea3
1
Parent(s):
5d5103b
Fix: Correct OAuth config API endpoint path
Browse filesπ Problem:
- Frontend calling /api/auth/oauth-config (404 error)
- Backend auth router has prefix '/auth' not '/api/auth'
- Endpoint should be /auth/oauth-config
β
Solution:
- Changed frontend API call from /api/auth/oauth-config to /auth/oauth-config
- Matches backend router prefix configuration
π§ Technical Details:
- auth router: APIRouter(prefix='/auth')
- Correct endpoint: /auth/oauth-config
- This should resolve 404 errors and allow OAuth config fetch
π― Expected Result:
- OAuth config API call should now succeed
- Should get client_id from backend
- Login process should work correctly
frontend/src/context/AuthContext.tsx
CHANGED
|
@@ -219,29 +219,29 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|
| 219 |
if (isHFSpaces) {
|
| 220 |
// In HF Spaces, get OAuth config from backend API
|
| 221 |
console.log("π Getting OAuth config from backend");
|
| 222 |
-
|
| 223 |
try {
|
| 224 |
-
const response = await fetch(
|
| 225 |
const oauthConfig = await response.json();
|
| 226 |
-
|
| 227 |
if (!oauthConfig.oauth_enabled) {
|
| 228 |
throw new Error("OAuth not enabled or configured on backend");
|
| 229 |
}
|
| 230 |
-
|
| 231 |
console.log("β
OAuth config received:", {
|
| 232 |
client_id: oauthConfig.client_id?.substring(0, 8) + "...",
|
| 233 |
scopes: oauthConfig.scopes,
|
| 234 |
-
provider_url: oauthConfig.provider_url
|
| 235 |
});
|
| 236 |
-
|
| 237 |
// Direct OAuth URL construction with backend-provided client_id
|
| 238 |
const baseUrl = window.location.origin;
|
| 239 |
const redirectUri = `${baseUrl}/oauth-callback`;
|
| 240 |
-
|
| 241 |
// Create state for CSRF protection
|
| 242 |
const state = Math.random().toString(36).substring(2, 15);
|
| 243 |
localStorage.setItem("oauth_state", state);
|
| 244 |
-
|
| 245 |
// Use HF OAuth endpoint with proper client_id from backend
|
| 246 |
const oauthUrl =
|
| 247 |
`${oauthConfig.provider_url}/oauth/authorize?` +
|
|
@@ -251,12 +251,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|
| 251 |
`scope=${encodeURIComponent(oauthConfig.scopes)}&` +
|
| 252 |
`state=${state}&` +
|
| 253 |
`prompt=consent`;
|
| 254 |
-
|
| 255 |
console.log("π Redirecting to HF OAuth with client_id");
|
| 256 |
window.location.href = oauthUrl;
|
| 257 |
-
|
| 258 |
} catch (configError) {
|
| 259 |
-
console.error(
|
|
|
|
|
|
|
|
|
|
| 260 |
throw new Error("OAuth configuration not available from backend");
|
| 261 |
}
|
| 262 |
} else {
|
|
|
|
| 219 |
if (isHFSpaces) {
|
| 220 |
// In HF Spaces, get OAuth config from backend API
|
| 221 |
console.log("π Getting OAuth config from backend");
|
| 222 |
+
|
| 223 |
try {
|
| 224 |
+
const response = await fetch("/auth/oauth-config");
|
| 225 |
const oauthConfig = await response.json();
|
| 226 |
+
|
| 227 |
if (!oauthConfig.oauth_enabled) {
|
| 228 |
throw new Error("OAuth not enabled or configured on backend");
|
| 229 |
}
|
| 230 |
+
|
| 231 |
console.log("β
OAuth config received:", {
|
| 232 |
client_id: oauthConfig.client_id?.substring(0, 8) + "...",
|
| 233 |
scopes: oauthConfig.scopes,
|
| 234 |
+
provider_url: oauthConfig.provider_url,
|
| 235 |
});
|
| 236 |
+
|
| 237 |
// Direct OAuth URL construction with backend-provided client_id
|
| 238 |
const baseUrl = window.location.origin;
|
| 239 |
const redirectUri = `${baseUrl}/oauth-callback`;
|
| 240 |
+
|
| 241 |
// Create state for CSRF protection
|
| 242 |
const state = Math.random().toString(36).substring(2, 15);
|
| 243 |
localStorage.setItem("oauth_state", state);
|
| 244 |
+
|
| 245 |
// Use HF OAuth endpoint with proper client_id from backend
|
| 246 |
const oauthUrl =
|
| 247 |
`${oauthConfig.provider_url}/oauth/authorize?` +
|
|
|
|
| 251 |
`scope=${encodeURIComponent(oauthConfig.scopes)}&` +
|
| 252 |
`state=${state}&` +
|
| 253 |
`prompt=consent`;
|
| 254 |
+
|
| 255 |
console.log("π Redirecting to HF OAuth with client_id");
|
| 256 |
window.location.href = oauthUrl;
|
|
|
|
| 257 |
} catch (configError) {
|
| 258 |
+
console.error(
|
| 259 |
+
"Failed to get OAuth config from backend:",
|
| 260 |
+
configError
|
| 261 |
+
);
|
| 262 |
throw new Error("OAuth configuration not available from backend");
|
| 263 |
}
|
| 264 |
} else {
|