Spaces:
Paused
Paused
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
from fastapi import HTTPException, Depends
|
| 3 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 4 |
-
from datetime import datetime, timedelta
|
| 5 |
import jwt
|
|
|
|
| 6 |
|
| 7 |
security = HTTPBearer()
|
| 8 |
|
|
@@ -56,7 +58,7 @@ def get_jwt_config():
|
|
| 56 |
# Cloud mode - use secrets from environment
|
| 57 |
jwt_secret = os.getenv("JWT_SECRET")
|
| 58 |
if not jwt_secret:
|
| 59 |
-
|
| 60 |
jwt_secret = "flare-admin-secret-key-change-in-production" # Fallback
|
| 61 |
else:
|
| 62 |
# On-premise mode - use .env file
|
|
@@ -69,7 +71,7 @@ def get_jwt_config():
|
|
| 69 |
"algorithm": os.getenv("JWT_ALGORITHM", "HS256"),
|
| 70 |
"expiration_hours": int(os.getenv("JWT_EXPIRATION_HOURS", "24"))
|
| 71 |
}
|
| 72 |
-
|
| 73 |
# ===================== Auth Helpers =====================
|
| 74 |
def create_token(username: str) -> str:
|
| 75 |
"""Create JWT token for user"""
|
|
|
|
| 1 |
+
|
| 2 |
import os
|
| 3 |
from fastapi import HTTPException, Depends
|
| 4 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 5 |
+
from datetime import datetime, timedelta, timezone
|
| 6 |
import jwt
|
| 7 |
+
from logger import log_info, log_warning
|
| 8 |
|
| 9 |
security = HTTPBearer()
|
| 10 |
|
|
|
|
| 58 |
# Cloud mode - use secrets from environment
|
| 59 |
jwt_secret = os.getenv("JWT_SECRET")
|
| 60 |
if not jwt_secret:
|
| 61 |
+
log_warning("⚠️ WARNING: JWT_SECRET not found in environment, using fallback")
|
| 62 |
jwt_secret = "flare-admin-secret-key-change-in-production" # Fallback
|
| 63 |
else:
|
| 64 |
# On-premise mode - use .env file
|
|
|
|
| 71 |
"algorithm": os.getenv("JWT_ALGORITHM", "HS256"),
|
| 72 |
"expiration_hours": int(os.getenv("JWT_EXPIRATION_HOURS", "24"))
|
| 73 |
}
|
| 74 |
+
|
| 75 |
# ===================== Auth Helpers =====================
|
| 76 |
def create_token(username: str) -> str:
|
| 77 |
"""Create JWT token for user"""
|