(20241231) Session Token now being received on SocketIO.
This commit is contained in:
@@ -107,6 +107,7 @@ def allow_origins(origin):
|
|||||||
|
|
||||||
sio = socketio.AsyncServer(
|
sio = socketio.AsyncServer(
|
||||||
cors_allowed_origins = allow_origins,
|
cors_allowed_origins = allow_origins,
|
||||||
|
allow_headers = ["X-Session-Token", "HTTP_X_SESSION_TOKEN"],
|
||||||
async_mode = "asgi"
|
async_mode = "asgi"
|
||||||
)
|
)
|
||||||
app = socketio.ASGIApp(sio)
|
app = socketio.ASGIApp(sio)
|
||||||
@@ -153,7 +154,10 @@ flags = {
|
|||||||
|
|
||||||
|
|
||||||
@sio.on(event = EVENT_CONNECT, namespace = NAMESPACE_MODULE)
|
@sio.on(event = EVENT_CONNECT, namespace = NAMESPACE_MODULE)
|
||||||
async def handle_connect(sid, environ) -> bool:
|
async def handle_connect(sid, environ, *args) -> bool:
|
||||||
|
|
||||||
|
session_token = environ.get("HTTP_X_SESSION_TOKEN")
|
||||||
|
if not session_token and len(args) > 0: session_token = args[0].get("X-Session-Token")
|
||||||
|
|
||||||
# Start the common background processes:
|
# Start the common background processes:
|
||||||
if not flags.get("initDone"):
|
if not flags.get("initDone"):
|
||||||
@@ -164,13 +168,15 @@ async def handle_connect(sid, environ) -> bool:
|
|||||||
async with lock:
|
async with lock:
|
||||||
connected_clients[sid] = {
|
connected_clients[sid] = {
|
||||||
"user": None,
|
"user": None,
|
||||||
"redisKey": f"io_{environ.get('HTTP_X_SESSION_TOKEN')}",
|
"redisKey": f"io_{session_token}",
|
||||||
"rooms": []
|
"rooms": []
|
||||||
}
|
}
|
||||||
|
|
||||||
# Allow/reject requests:
|
# Allow/reject requests:
|
||||||
printer(sid)
|
printer(sid)
|
||||||
|
print("SESSION TOKEN:", session_token)
|
||||||
# print("ENVIRON:", json.to_string(environ, default = str))
|
# print("ENVIRON:", json.to_string(environ, default = str))
|
||||||
|
# print("ARGS:", args)
|
||||||
while redis_cache is None: await asyncio.sleep(0.5)
|
while redis_cache is None: await asyncio.sleep(0.5)
|
||||||
result = await redis_cache.set(
|
result = await redis_cache.set(
|
||||||
key = connected_clients[sid]["redisKey"],
|
key = connected_clients[sid]["redisKey"],
|
||||||
|
|||||||
Reference in New Issue
Block a user