From 7a38aad0cc1ea317f243c246fcc5f059ec96ffb8 Mon Sep 17 00:00:00 2001 From: mcarlton00 Date: Fri, 27 Mar 2026 17:47:24 -0400 Subject: [PATCH] Fix websocket authentication --- jellyfin_kodi/jellyfin/ws_client.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/jellyfin_kodi/jellyfin/ws_client.py b/jellyfin_kodi/jellyfin/ws_client.py index 65bce3b6..c52ea781 100644 --- a/jellyfin_kodi/jellyfin/ws_client.py +++ b/jellyfin_kodi/jellyfin/ws_client.py @@ -47,20 +47,34 @@ class WSClient(threading.Thread): def run(self): monitor = xbmc.Monitor() - token = self.client.config.data["auth.token"] - device_id = self.client.config.data["app.device_id"] server = self.client.config.data["auth.server"] server = ( server.replace("https://", "wss://") if server.startswith("https") else server.replace("http://", "ws://") ) - wsc_url = "%s/socket?ApiKey=%s&device_id=%s" % (server, token, device_id) + wsc_url = "%s/socket" % server + # Build authorization header for websocket connection + auth_params = {} + if "app.device_name" in self.client.config.data: + auth_params.update( + { + "Client": self.client.config.data["app.name"], + "Device": self.client.config.data["app.device_name"], + "DeviceId": self.client.config.data["app.device_id"], + "Version": self.client.config.data["app.version"], + } + ) + if "auth.token" in self.client.config.data: + auth_params["Token"] = self.client.config.data["auth.token"] + auth_line = ", ".join(f'{k}="{v}"' for k, v in auth_params.items()) + ws_headers = {"Authorization": f"MediaBrowser {auth_line}"} LOG.info("Websocket url: %s", wsc_url) self.wsc = websocket.WebSocketApp( wsc_url, + header=ws_headers, on_open=lambda ws: self.on_open(ws), on_message=lambda ws, message: self.on_message(ws, message), on_error=lambda ws, error: self.on_error(ws, error),