Spaces:
Running
Running
Update helper/subscriptions.py
Browse files- helper/subscriptions.py +16 -8
helper/subscriptions.py
CHANGED
|
@@ -263,16 +263,24 @@ async def fetch_subscription(jwt: str):
|
|
| 263 |
}
|
| 264 |
|
| 265 |
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
jwt_identity = resolve_jwt_identity(token)
|
| 268 |
if jwt_identity is not None:
|
| 269 |
return jwt_identity
|
| 270 |
|
| 271 |
-
|
| 272 |
-
if
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
-
return {"error": "Invalid or expired credentials"}
|
| 276 |
|
| 277 |
|
| 278 |
def resolve_jwt_identity(token: str):
|
|
@@ -320,17 +328,17 @@ async def resolve_api_key_identity(token: str):
|
|
| 320 |
return None
|
| 321 |
|
| 322 |
if row.get("revoked_at") is not None:
|
| 323 |
-
|
| 324 |
|
| 325 |
expires_at = row.get("expires_at")
|
| 326 |
if expires_at is not None and expires_at <= datetime.now(timezone.utc):
|
| 327 |
-
|
| 328 |
|
| 329 |
email = row.get("email")
|
| 330 |
created_at = row.get("user_created_at")
|
| 331 |
user_id = row.get("user_id")
|
| 332 |
if not isinstance(email, str) or not email.strip():
|
| 333 |
-
|
| 334 |
|
| 335 |
await execute_query(
|
| 336 |
"""
|
|
|
|
| 263 |
}
|
| 264 |
|
| 265 |
|
| 266 |
+
from fastapi import HTTPException
|
| 267 |
+
|
| 268 |
+
async def resolve_token_identity(token: str | None):
|
| 269 |
+
if not token:
|
| 270 |
+
return None
|
| 271 |
+
|
| 272 |
jwt_identity = resolve_jwt_identity(token)
|
| 273 |
if jwt_identity is not None:
|
| 274 |
return jwt_identity
|
| 275 |
|
| 276 |
+
api_identity = await resolve_api_key_identity(token)
|
| 277 |
+
if api_identity is not None:
|
| 278 |
+
if "error" in api_identity:
|
| 279 |
+
raise HTTPException(status_code=401, detail=api_identity["error"])
|
| 280 |
+
return api_identity
|
| 281 |
+
|
| 282 |
+
raise HTTPException(status_code=401, detail="Invalid API key or token")
|
| 283 |
|
|
|
|
| 284 |
|
| 285 |
|
| 286 |
def resolve_jwt_identity(token: str):
|
|
|
|
| 328 |
return None
|
| 329 |
|
| 330 |
if row.get("revoked_at") is not None:
|
| 331 |
+
raise HTTPException(status_code=401, detail="Invalid API key or token")
|
| 332 |
|
| 333 |
expires_at = row.get("expires_at")
|
| 334 |
if expires_at is not None and expires_at <= datetime.now(timezone.utc):
|
| 335 |
+
raise HTTPException(status_code=401, detail="Invalid API key or token")
|
| 336 |
|
| 337 |
email = row.get("email")
|
| 338 |
created_at = row.get("user_created_at")
|
| 339 |
user_id = row.get("user_id")
|
| 340 |
if not isinstance(email, str) or not email.strip():
|
| 341 |
+
raise HTTPException(status_code=401, detail="Invalid API key or token")
|
| 342 |
|
| 343 |
await execute_query(
|
| 344 |
"""
|