Skip to content

Commit bf1e1c4

Browse files
committed
Manage session-id through reverse proxy
Fix #1222
1 parent 0f6103e commit bf1e1c4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

TM1py/Services/RestService.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,13 @@ def _start_session(self, user: str, password: str, decode_b64: bool = False, nam
783783
raise ValueError(f"No response returned from URL: '{self._auth_url}'. "
784784
f"Please double check your address and port number in the URL.")
785785

786-
787786
finally:
787+
# If the TM1 REST API is routed through a reverse proxy that alters the expected URL,
788+
# we explicitly re-set the 'TM1SessionId' cookie to maintain session continuity.
789+
session_id = self._s.cookies.pop('TM1SessionId', None)
790+
if session_id is not None:
791+
self._s.cookies.set('TM1SessionId', session_id)
792+
788793
# After we have session cookie, drop the Authorization Header
789794
self.remove_http_header('Authorization')
790795

@@ -917,7 +922,8 @@ def verify_response(response: Response):
917922

918923
@staticmethod
919924
def _build_authorization_token(user: str, password: str, namespace: str = None, gateway: str = None,
920-
cam_passport: str = None, verify: bool = False, cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
925+
cam_passport: str = None, verify: bool = False,
926+
cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
921927
""" Build the Authorization Header for CAM and Native Security
922928
"""
923929
if cam_passport:
@@ -929,7 +935,8 @@ def _build_authorization_token(user: str, password: str, namespace: str = None,
929935

930936
@staticmethod
931937
def _build_authorization_token_cam(user: str = None, password: str = None, namespace: str = None,
932-
gateway: str = None, verify: bool = False, cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
938+
gateway: str = None, verify: bool = False,
939+
cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
933940
if gateway:
934941
try:
935942
HttpNegotiateAuth

0 commit comments

Comments
 (0)