Skip to content

Commit 609e5af

Browse files
committed
Fix session retrieval
1 parent 3b45936 commit 609e5af

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

lib/galaxy/webapps/galaxy/api/context.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Optional,
55
)
66

7-
from fastapi import Request
8-
97
from galaxy import web
108
from galaxy.managers.configuration import ConfigurationManager
119
from galaxy.managers.context import ProvidesUserContext
@@ -36,28 +34,12 @@ class FastAPIContext:
3634
user_serializer: CurrentUserSerializer = depends(CurrentUserSerializer)
3735

3836
@router.get("/context", summary="Return bootstrapped client context")
39-
def index(self, request: Request, trans: ProvidesUserContext = DependsOnTrans) -> ContextResponse:
37+
def index(self, trans: ProvidesUserContext = DependsOnTrans) -> ContextResponse:
4038
config = self.configuration_manager.get_configuration(trans, SerializationParams(view="all"))
39+
session_id = trans.galaxy_session.id if trans.galaxy_session else None
4140
return ContextResponse(
4241
config=config,
4342
root=web.url_for("/"),
44-
session_csrf_token=self._get_csrf_token(trans, request),
43+
session_csrf_token=trans.app.security.encode_id(session_id, kind="csrf") if session_id else None,
4544
user=self.user_serializer.serialize_to_view(trans.user, "detailed"),
4645
)
47-
48-
def _get_csrf_token(self, trans: ProvidesUserContext, request: Request):
49-
cookie = request.cookies.get("galaxysession")
50-
if not cookie:
51-
return None
52-
try:
53-
session_key = trans.app.security.decode_guid(cookie)
54-
session = (
55-
trans.sa_session.query(trans.app.model.GalaxySession)
56-
.filter_by(session_key=session_key, is_valid=True)
57-
.first()
58-
)
59-
if session:
60-
return trans.app.security.encode_id(session.id, kind="csrf")
61-
except Exception:
62-
log.debug("Failed to derive CSRF token", exc_info=True)
63-
return None

0 commit comments

Comments
 (0)