mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2026-04-27 22:05:38 +00:00
Fix websocket authentication
This commit is contained in:
parent
fa0ccfd8f6
commit
7a38aad0cc
1 changed files with 17 additions and 3 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue