Spaces:
Sleeping
Sleeping
Commit
·
434c40e
1
Parent(s):
1670330
Add 'itsdangerous' dependency for session management and enhance OAuth configuration with scope validation and warnings for unsupported scopes in Hugging Face Spaces.
Browse files- pyproject.toml +1 -0
- utils/environment.py +17 -1
pyproject.toml
CHANGED
|
@@ -30,6 +30,7 @@ dependencies = [
|
|
| 30 |
"uvicorn>=0.34.0", # ✅ 核心
|
| 31 |
"httpx>=0.27.0", # ✅ 核心
|
| 32 |
"python-multipart>=0.0.6,<1.0.0", # ✅ 核心
|
|
|
|
| 33 |
|
| 34 |
# ===== 数据层 =====
|
| 35 |
"sqlalchemy>=2.0.0", # ✅ 核心 (36+ 使用)
|
|
|
|
| 30 |
"uvicorn>=0.34.0", # ✅ 核心
|
| 31 |
"httpx>=0.27.0", # ✅ 核心
|
| 32 |
"python-multipart>=0.0.6,<1.0.0", # ✅ 核心
|
| 33 |
+
"itsdangerous>=2.0.0", # ✅ Session middleware dependency
|
| 34 |
|
| 35 |
# ===== 数据层 =====
|
| 36 |
"sqlalchemy>=2.0.0", # ✅ 核心 (36+ 使用)
|
utils/environment.py
CHANGED
|
@@ -78,10 +78,26 @@ def get_oauth_config() -> Optional[Dict[str, str]]:
|
|
| 78 |
if not should_enable_auth():
|
| 79 |
return None
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
oauth_config = {
|
| 82 |
"client_id": os.getenv("OAUTH_CLIENT_ID"),
|
| 83 |
"client_secret": os.getenv("OAUTH_CLIENT_SECRET"),
|
| 84 |
-
"scopes":
|
| 85 |
"provider_url": os.getenv("OPENID_PROVIDER_URL", "https://huggingface.co"),
|
| 86 |
}
|
| 87 |
|
|
|
|
| 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():
|
| 86 |
+
unsupported_scopes = []
|
| 87 |
+
for scope in scopes.split():
|
| 88 |
+
if scope not in ["email", "read-repos", "write-repos", "manage-repos",
|
| 89 |
+
"read-mcp", "write-discussions", "read-billing",
|
| 90 |
+
"inference-api", "jobs", "webhooks"]:
|
| 91 |
+
unsupported_scopes.append(scope)
|
| 92 |
+
|
| 93 |
+
if unsupported_scopes:
|
| 94 |
+
print(f"⚠️ Warning: Unsupported OAuth scopes detected: {unsupported_scopes}")
|
| 95 |
+
print("📝 Supported HF scopes: email, read-repos, write-repos, manage-repos, read-mcp, write-discussions, read-billing, inference-api, jobs, webhooks")
|
| 96 |
+
|
| 97 |
oauth_config = {
|
| 98 |
"client_id": os.getenv("OAUTH_CLIENT_ID"),
|
| 99 |
"client_secret": os.getenv("OAUTH_CLIENT_SECRET"),
|
| 100 |
+
"scopes": scopes,
|
| 101 |
"provider_url": os.getenv("OPENID_PROVIDER_URL", "https://huggingface.co"),
|
| 102 |
}
|
| 103 |
|