Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage session-id through reverse proxy #1223

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions TM1py/Services/RestService.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,13 @@ def _start_session(self, user: str, password: str, decode_b64: bool = False, nam
raise ValueError(f"No response returned from URL: '{self._auth_url}'. "
f"Please double check your address and port number in the URL.")


finally:
# If the TM1 REST API is routed through a reverse proxy that alters the expected URL,
# we explicitly re-set the 'TM1SessionId' cookie to maintain session continuity.
session_id = self._s.cookies.pop('TM1SessionId', None)
if session_id is not None:
self._s.cookies.set('TM1SessionId', session_id)

# After we have session cookie, drop the Authorization Header
self.remove_http_header('Authorization')

Expand Down Expand Up @@ -917,7 +922,8 @@ def verify_response(response: Response):

@staticmethod
def _build_authorization_token(user: str, password: str, namespace: str = None, gateway: str = None,
cam_passport: str = None, verify: bool = False, cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
cam_passport: str = None, verify: bool = False,
cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
""" Build the Authorization Header for CAM and Native Security
"""
if cam_passport:
Expand All @@ -929,7 +935,8 @@ def _build_authorization_token(user: str, password: str, namespace: str = None,

@staticmethod
def _build_authorization_token_cam(user: str = None, password: str = None, namespace: str = None,
gateway: str = None, verify: bool = False, cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
gateway: str = None, verify: bool = False,
cert: Optional[Union[str, Tuple[str, str]]] = None) -> str:
if gateway:
try:
HttpNegotiateAuth
Expand Down