wu981526092 commited on
Commit
d1a53e8
·
1 Parent(s): 0a06f26
Files changed (2) hide show
  1. backend/app.py +9 -7
  2. utils/environment.py +5 -2
backend/app.py CHANGED
@@ -53,20 +53,22 @@ app.add_middleware(
53
  allow_headers=["*"],
54
  )
55
 
56
- # Add conditional authentication middleware
57
- app.add_middleware(ConditionalAuthMiddleware)
58
-
59
- # Add usage tracking middleware (after auth, to track authenticated requests)
60
- app.add_middleware(UsageTrackingMiddleware)
61
-
62
- # Add session middleware (last, so it's innermost and processes requests first)
63
  session_secret = os.getenv("SESSION_SECRET_KEY") or secrets.token_urlsafe(32)
64
  app.add_middleware(
65
  SessionMiddleware,
66
  secret_key=session_secret,
67
  max_age=86400, # 24 hours
 
 
68
  )
69
 
 
 
 
 
 
 
70
  # Mount datasets directory for accessing json files
71
  app.mount("/data", StaticFiles(directory="datasets"), name="data")
72
 
 
53
  allow_headers=["*"],
54
  )
55
 
56
+ # Add session middleware (second, so auth can read session data)
 
 
 
 
 
 
57
  session_secret = os.getenv("SESSION_SECRET_KEY") or secrets.token_urlsafe(32)
58
  app.add_middleware(
59
  SessionMiddleware,
60
  secret_key=session_secret,
61
  max_age=86400, # 24 hours
62
+ same_site="lax", # Better for OAuth redirects
63
+ https_only=False, # Will be True in production via reverse proxy
64
  )
65
 
66
+ # Add conditional authentication middleware (after session)
67
+ app.add_middleware(ConditionalAuthMiddleware)
68
+
69
+ # Add usage tracking middleware (last, to track authenticated requests)
70
+ app.add_middleware(UsageTrackingMiddleware)
71
+
72
  # Mount datasets directory for accessing json files
73
  app.mount("/data", StaticFiles(directory="datasets"), name="data")
74
 
utils/environment.py CHANGED
@@ -78,8 +78,11 @@ def get_oauth_config() -> Optional[Dict[str, str]]:
78
  if not should_enable_auth():
79
  return None
80
 
81
- # Get scopes with fallback to HF-compatible default
82
- scopes = os.getenv("OAUTH_SCOPES", "read-repos")
 
 
 
83
 
84
  # Warn about unsupported scopes for HF Spaces
85
  if is_huggingface_space():
 
78
  if not should_enable_auth():
79
  return None
80
 
81
+ # Force HF-compatible scope for HF Spaces, ignore environment variable
82
+ if is_huggingface_space():
83
+ scopes = "read-repos" # Only use supported scope
84
+ else:
85
+ scopes = os.getenv("OAUTH_SCOPES", "read-repos")
86
 
87
  # Warn about unsupported scopes for HF Spaces
88
  if is_huggingface_space():