From 3b2b658881684cda271efd7c6cdbce0e36effdcd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 22 Jan 2021 12:47:38 +0000 Subject: [PATCH 1/2] Add `--force-localserver-for-auth` CL arg to EDMarketConnector --- EDMarketConnector.py | 8 ++++++++ config.py | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index eb9b81eb..5b2ac883 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -55,6 +55,11 @@ if __name__ == '__main__': # noqa: C901 action='store_true' ) + parser.add_argument('--force-localserver-for-auth', + help='Force EDMC to use a localhost webserver for Frontier Auth callback', + action='store_true' + ) + args = parser.parse_args() if args.trace: @@ -63,6 +68,9 @@ if __name__ == '__main__': # noqa: C901 else: edmclogger.set_channels_loglevel(logging.DEBUG) + if args.force_localserver_for_auth: + config.set_auth_force_localserver() + def no_other_instance_running() -> bool: # noqa: CCR001 """ Ensure only one copy of the app is running for the configured journal directory. diff --git a/config.py b/config.py index 7d077d2b..d9ac1099 100644 --- a/config.py +++ b/config.py @@ -118,6 +118,7 @@ class Config(object): def __init__(self): self.__in_shutdown = False # Is the application currently shutting down ? + self.__auth_force_localserver = False # Should we use localhost for auth callback ? self.app_dir = join(NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname) if not isdir(self.app_dir): @@ -186,10 +187,18 @@ class Config(object): def shutting_down(self) -> bool: return self.__in_shutdown + def set_auth_force_localserver(self): + self.__auth_force_localserver = True + + @property + def auth_force_localserver(self) -> bool: + return self.__auth_force_localserver + elif platform=='win32': def __init__(self): self.__in_shutdown = False # Is the application currently shutting down ? + self.__auth_force_localserver = False # Should we use localhost for auth callback ? self.app_dir = join(KnownFolderPath(FOLDERID_LocalAppData), appname) if not isdir(self.app_dir): @@ -285,12 +294,20 @@ class Config(object): def shutting_down(self) -> bool: return self.__in_shutdown + def set_auth_force_localserver(self): + self.__auth_force_localserver = True + + @property + def auth_force_localserver(self) -> bool: + return self.__auth_force_localserver + elif platform=='linux': SECTION = 'config' def __init__(self): self.__in_shutdown = False # Is the application currently shutting down ? + self.__auth_force_localserver = False # Should we use localhost for auth callback ? # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname) @@ -371,6 +388,13 @@ class Config(object): def shutting_down(self) -> bool: return self.__in_shutdown + def set_auth_force_localserver(self): + self.__auth_force_localserver = True + + @property + def auth_force_localserver(self) -> bool: + return self.__auth_force_localserver + def _escape(self, val): return str(val).replace(u'\\', u'\\\\').replace(u'\n', u'\\n').replace(u';', u'\\;') From e1757a3a993b67bab839a878d0a1a8f10f4a1534 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 22 Jan 2021 13:00:02 +0000 Subject: [PATCH 2/2] protocol: Don't use win32-specific edmc://auth if `--force-localserver-for-auth` Tested with a build/install and run with: "c:\Program Files (x86)\EDMarketConnector\EDMarketConnector.exe" --force-localserver-for-auth --trace 2021-01-22 12:57:11.020 - TRACE - protocol.ProtocolHandler.__init__:222: Web ser ver listening on http://localhost:53657/auth --- protocol.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protocol.py b/protocol.py index 886608e6..9dd9aba5 100644 --- a/protocol.py +++ b/protocol.py @@ -7,7 +7,9 @@ import sys from config import appname, config from constants import protocolhandler_redirect +from EDMCLogging import get_main_logger +logger = get_main_logger() if sys.platform == 'win32': from ctypes import * @@ -74,7 +76,7 @@ if sys.platform == 'darwin' and getattr(sys, 'frozen', False): protocolhandler.master.after(ProtocolHandler.POLL, protocolhandler.poll) -elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine: +elif sys.platform == 'win32' and getattr(sys, 'frozen', False) and not is_wine and not config.auth_force_localserver: class WNDCLASS(Structure): _fields_ = [('style', UINT), @@ -217,6 +219,7 @@ else: # Linux / Run from source GenericProtocolHandler.__init__(self) self.httpd = HTTPServer(('localhost', 0), HTTPRequestHandler) self.redirect = 'http://localhost:%d/auth' % self.httpd.server_port + logger.trace(f'Web server listening on {self.redirect}') self.thread = None def start(self, master):