From 77ec993f9531d58e3838ceffa544af304df025a2 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Mon, 10 Sep 2018 19:16:11 -0500 Subject: [PATCH] Adjust new auth method for remote access Keep old method of auth if remote connection is unsecured --- resources/lib/dialogs/loginmanual.py | 4 +++- resources/lib/emby/core/connection_manager.py | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/resources/lib/dialogs/loginmanual.py b/resources/lib/dialogs/loginmanual.py index 0a1125be..5c884628 100644 --- a/resources/lib/dialogs/loginmanual.py +++ b/resources/lib/dialogs/loginmanual.py @@ -119,7 +119,9 @@ class LoginManual(xbmcgui.WindowXMLDialog): def _login(self, username, password): - result = self.connect_manager['login'](self.connect_manager['server-address'], username, password) + mode = self.connect_manager['server-mode'] + server = self.connect_manager['server-address'] + result = self.connect_manager['login'](server, username, password, False if mode == 1 and server.startswith('http://') else True) if not result: self._error(ERROR['Invalid'], _('invalid_auth')) diff --git a/resources/lib/emby/core/connection_manager.py b/resources/lib/emby/core/connection_manager.py index 770c971e..1e105756 100644 --- a/resources/lib/emby/core/connection_manager.py +++ b/resources/lib/emby/core/connection_manager.py @@ -98,6 +98,9 @@ class ConnectionManager(object): return get_server_address(server, server['LastConnectionMode']) elif key == "revoke-token": return self.revoke_token() + elif key == "server-mode": + server = self.get_server_info(self.server_id) + return server['LastConnectionMode'] return @@ -188,7 +191,7 @@ class ConnectionManager(object): return result - def login(self, server, username, password="", options={}): + def login(self, server, username, password=None, clear=True, options={}): if not username: raise AttributeError("username cannot be empty") @@ -197,14 +200,18 @@ class ConnectionManager(object): raise AttributeError("server cannot be empty") try: - result = self._request_url({ + request = { 'type': "POST", 'url': self.get_emby_url(server, "Users/AuthenticateByName"), 'json': { 'username': username, - 'pw': password or "" + 'password': hashlib.sha1(password or "").hexdigest(), } - }, False) + } + if clear: + request['json']['pw'] = password or "" + + result = self._request_url(request, False) except Exception as error: # Failed to login LOG.error(error) return False