fffiloni commited on
Commit
00f5427
·
verified ·
1 Parent(s): 28c5d54

Upload 4 files

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +40 -4
README.md CHANGED
@@ -133,4 +133,4 @@ See `CHANGELOG_V194.md` for the Model Pre-scan Decision Card UI pass.
133
  See `CHANGELOG_V195.md` for the Runtime CSS Cleanup with Legacy Safety Net pass.
134
 
135
 
136
- Current release: Agentic Space Factory v198.23.1.
 
133
  See `CHANGELOG_V195.md` for the Runtime CSS Cleanup with Legacy Safety Net pass.
134
 
135
 
136
+ Current release: Agentic Space Factory v198.23.2.
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from __future__ import annotations
2
 
3
  import json
 
4
  import re
5
  from pathlib import Path
6
  from typing import Any
@@ -408,11 +409,11 @@ def register_custom_routes(fastapi_app: FastAPI) -> None:
408
 
409
  @fastapi_app.get("/login/huggingface")
410
  async def login_redirect(): # type: ignore[no-untyped-def]
411
- return RedirectResponse("/oauth/huggingface/login")
412
 
413
  @fastapi_app.get("/logout")
414
  async def logout_redirect(): # type: ignore[no-untyped-def]
415
- return RedirectResponse("/oauth/huggingface/logout")
416
 
417
  @fastapi_app.get("/api/app-info")
418
  async def api_app_info(request: Request): # type: ignore[no-untyped-def]
@@ -522,8 +523,43 @@ def register_custom_routes(fastapi_app: FastAPI) -> None:
522
 
523
  @fastapi_app.get("/api/oauth/diagnostics")
524
  async def api_oauth_diagnostics(request: Request): # type: ignore[no-untyped-def]
525
- ctx = extract_oauth_context(request)
526
- return JSONResponse({"user": public_oauth_context(ctx), "token_identity": verify_token_identity(ctx)})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
527
 
528
  @fastapi_app.get("/api/billing/status")
529
  async def api_billing_status(request: Request): # type: ignore[no-untyped-def]
 
1
  from __future__ import annotations
2
 
3
  import json
4
+ import os
5
  import re
6
  from pathlib import Path
7
  from typing import Any
 
409
 
410
  @fastapi_app.get("/login/huggingface")
411
  async def login_redirect(): # type: ignore[no-untyped-def]
412
+ return RedirectResponse("/oauth/huggingface/login?_target_url=/")
413
 
414
  @fastapi_app.get("/logout")
415
  async def logout_redirect(): # type: ignore[no-untyped-def]
416
+ return RedirectResponse("/oauth/huggingface/logout?_target_url=/")
417
 
418
  @fastapi_app.get("/api/app-info")
419
  async def api_app_info(request: Request): # type: ignore[no-untyped-def]
 
523
 
524
  @fastapi_app.get("/api/oauth/diagnostics")
525
  async def api_oauth_diagnostics(request: Request): # type: ignore[no-untyped-def]
526
+ """Public-safe OAuth diagnostics for iframe/sign-in troubleshooting.
527
+
528
+ This endpoint never exposes secrets. It is intentionally readable while
529
+ signed out so the UI/operator can tell whether OAuth routes and Space
530
+ metadata-derived environment variables are present before login works.
531
+ """
532
+ env_status = {
533
+ "space_id_present": bool(os.getenv("SPACE_ID")),
534
+ "space_host_present": bool(os.getenv("SPACE_HOST")),
535
+ "oauth_client_id_present": bool(os.getenv("OAUTH_CLIENT_ID")),
536
+ "oauth_client_secret_present": bool(os.getenv("OAUTH_CLIENT_SECRET")),
537
+ "oauth_scopes_present": bool(os.getenv("OAUTH_SCOPES")),
538
+ "openid_provider_url_present": bool(os.getenv("OPENID_PROVIDER_URL")),
539
+ }
540
+ try:
541
+ ctx = extract_oauth_context(request)
542
+ except HTTPException as exc:
543
+ return JSONResponse(
544
+ {
545
+ "authenticated": False,
546
+ "reason": exc.detail,
547
+ "oauth_env": env_status,
548
+ "login_url": "/oauth/huggingface/login?_target_url=/",
549
+ "logout_url": "/oauth/huggingface/logout?_target_url=/",
550
+ "embedded_login_advice": "Open sign-in in a new tab/window when the Space is embedded in an iframe.",
551
+ }
552
+ )
553
+ return JSONResponse(
554
+ {
555
+ "authenticated": True,
556
+ "user": public_oauth_context(ctx),
557
+ "token_identity": verify_token_identity(ctx),
558
+ "oauth_env": env_status,
559
+ "login_url": "/oauth/huggingface/login?_target_url=/",
560
+ "logout_url": "/oauth/huggingface/logout?_target_url=/",
561
+ }
562
+ )
563
 
564
  @fastapi_app.get("/api/billing/status")
565
  async def api_billing_status(request: Request): # type: ignore[no-untyped-def]