wu981526092 commited on
Commit
1670330
·
1 Parent(s): c8243d5

Update session management in FastAPI app, modify OAuth scopes in environment configuration, and enhance .env.example with session security details.

Browse files
Files changed (4) hide show
  1. .env.example +3 -0
  2. README.md +1 -2
  3. backend/app.py +3 -1
  4. utils/environment.py +1 -1
.env.example CHANGED
@@ -91,3 +91,6 @@ PYTHONPATH=/app
91
  # If deploying to Hugging Face Spaces, these are automatically set:
92
  # SPACE_ID=your-username/space-name
93
  # SPACE_HOST=https://your-username-space-name.hf.space
 
 
 
 
91
  # If deploying to Hugging Face Spaces, these are automatically set:
92
  # SPACE_ID=your-username/space-name
93
  # SPACE_HOST=https://your-username-space-name.hf.space
94
+
95
+ # Session Security (Optional - auto-generated if not set)
96
+ # SESSION_SECRET_KEY=your-secure-random-string-here
README.md CHANGED
@@ -9,8 +9,7 @@ license: mit
9
  app_port: 7860
10
  hf_oauth: true
11
  hf_oauth_scopes:
12
- - openid
13
- - profile
14
  hf_oauth_expiration_minutes: 480
15
  ---
16
 
 
9
  app_port: 7860
10
  hf_oauth: true
11
  hf_oauth_scopes:
12
+ - read-repos
 
13
  hf_oauth_expiration_minutes: 480
14
  ---
15
 
backend/app.py CHANGED
@@ -5,6 +5,7 @@ This module defines the FastAPI application and routes for the agent monitoring
5
 
6
  import logging
7
  import os
 
8
  from pathlib import Path
9
  import sys
10
  from fastapi import FastAPI, Request, status
@@ -43,9 +44,10 @@ logger = logging.getLogger("agent_monitoring_server")
43
  app = FastAPI(title="Agent Monitoring System", version="1.0.0")
44
 
45
  # Add session middleware (required for OAuth)
 
46
  app.add_middleware(
47
  SessionMiddleware,
48
- secret_key=os.getenv("SESSION_SECRET_KEY", "your-secret-key-change-in-production"),
49
  max_age=86400, # 24 hours
50
  )
51
 
 
5
 
6
  import logging
7
  import os
8
+ import secrets
9
  from pathlib import Path
10
  import sys
11
  from fastapi import FastAPI, Request, status
 
44
  app = FastAPI(title="Agent Monitoring System", version="1.0.0")
45
 
46
  # Add session middleware (required for OAuth)
47
+ session_secret = os.getenv("SESSION_SECRET_KEY") or secrets.token_urlsafe(32)
48
  app.add_middleware(
49
  SessionMiddleware,
50
+ secret_key=session_secret,
51
  max_age=86400, # 24 hours
52
  )
53
 
utils/environment.py CHANGED
@@ -81,7 +81,7 @@ def get_oauth_config() -> Optional[Dict[str, str]]:
81
  oauth_config = {
82
  "client_id": os.getenv("OAUTH_CLIENT_ID"),
83
  "client_secret": os.getenv("OAUTH_CLIENT_SECRET"),
84
- "scopes": os.getenv("OAUTH_SCOPES", "openid profile"),
85
  "provider_url": os.getenv("OPENID_PROVIDER_URL", "https://huggingface.co"),
86
  }
87
 
 
81
  oauth_config = {
82
  "client_id": os.getenv("OAUTH_CLIENT_ID"),
83
  "client_secret": os.getenv("OAUTH_CLIENT_SECRET"),
84
+ "scopes": os.getenv("OAUTH_SCOPES", "read-repos"),
85
  "provider_url": os.getenv("OPENID_PROVIDER_URL", "https://huggingface.co"),
86
  }
87