-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_config.py
More file actions
45 lines (37 loc) · 1.48 KB
/
Copy pathsession_config.py
File metadata and controls
45 lines (37 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import logging
from starlette.middleware.sessions import SessionMiddleware
logger = logging.getLogger(__name__)
def get_session_config():
"""
Get standardized session configuration that matches DungeonMindServer.
This ensures consistent session management across all DungeonMind apps.
"""
secret_key = os.getenv("SESSION_SECRET_KEY")
if not secret_key:
raise ValueError("SESSION_SECRET_KEY environment variable must be set")
# Environment-based configuration
environment = os.getenv('ENVIRONMENT', 'development')
is_production = environment == 'production'
config = {
"secret_key": secret_key,
"session_cookie": "dungeonmind_session", # Standardized cookie name
"max_age": 24 * 60 * 60, # 24 hours in seconds
"path": "/",
"https_only": is_production, # Only HTTPS in production
"same_site": "lax", # Consistent with main auth service
}
# Only add domain in production
if is_production:
config["domain"] = ".dungeonmind.net"
logger.info(f"Session config for {environment} environment: HTTPS={is_production}")
return config
def add_session_middleware(app):
"""
Add standardized session middleware to StoreGenerator app.
Args:
app: FastAPI application instance
"""
config = get_session_config()
app.add_middleware(SessionMiddleware, **config)
logger.info("Added standardized session middleware to StoreGenerator")