From e3d2fa40b7ef57b7fbcd4bd66b1a2e778c1829f8 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Fri, 5 Mar 2021 16:27:23 +0000 Subject: [PATCH 1/3] Add Steam and EGS to Frontier Auth audiences. --- companion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion.py b/companion.py index 1be9d0fa..b75d39ae 100644 --- a/companion.py +++ b/companion.py @@ -277,7 +277,7 @@ class Auth(object): logger.info(f'Trying auth from scratch for Commander "{self.cmdr}"') challenge = self.base64_url_encode(hashlib.sha256(self.verifier).digest()) webbrowser.open( - f'{SERVER_AUTH}{URL_AUTH}?response_type=code&audience=frontier&scope=capi&client_id={CLIENT_ID}&code_challenge={challenge}&code_challenge_method=S256&state={self.state}&redirect_uri={protocolhandler.redirect}' # noqa: E501 # I cant make this any shorter + f'{SERVER_AUTH}{URL_AUTH}?response_type=code&audience=frontier,steam,epic&scope=capi&client_id={CLIENT_ID}&code_challenge={challenge}&code_challenge_method=S256&state={self.state}&redirect_uri={protocolhandler.redirect}' # noqa: E501 # I cant make this any shorter ) return None From b11be09b56f97da9b0b8796024307650bb19a68e Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Fri, 5 Mar 2021 16:57:02 +0000 Subject: [PATCH 2/3] CAPI: Handle when we get no 'commander' in returned data. I was testing the new Steam or Epic CAPI auth. My EGS account hasn't yet been used, so has no commander attached. EDMC thinks the auth has succeeded in this case, but hitting 'Update' causes it to error because the returned data is empty. So, add some checks for lack of 'commander' key and a specific message "CAPI: No commander data returned" for status line. Without this there's a KeyError exception thrown, causing the status line to just get 'commander' in it, which isn't helpful. --- EDMarketConnector.py | 10 +++++++++- L10n/en.template | 3 +++ companion.py | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 73f15e67..6f4b8c7c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -662,17 +662,25 @@ class AppWindow(object): config.set('querytime', querytime) # Validation - if not data.get('commander', {}).get('name'): + if 'commander' not in data: + # This can happen with EGS Auth if no commander created yet + self.status['text'] = _('CAPI: No commander data returned') + + elif not data.get('commander', {}).get('name'): self.status['text'] = _("Who are you?!") # Shouldn't happen + elif (not data.get('lastSystem', {}).get('name') or (data['commander'].get('docked') and not data.get('lastStarport', {}).get('name'))): # Only care if docked self.status['text'] = _("Where are you?!") # Shouldn't happen + elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'): self.status['text'] = _("What are you flying?!") # Shouldn't happen + elif monitor.cmdr and data['commander']['name'] != monitor.cmdr: # Companion API return doesn't match Journal raise companion.CmdrError() + elif ((auto_update and not data['commander'].get('docked')) or (data['lastSystem']['name'] != monitor.system) or ((data['commander']['docked'] diff --git a/L10n/en.template b/L10n/en.template index 23b4abcd..ef8f7399 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -46,6 +46,9 @@ /* Folder selection button on Windows. [prefs.py] */ "Browse..." = "Browse..."; +/* No 'commander' data in CAPI [EDMarketConnector.py] */ +"CAPI: No commander data returned" = "CAPI: No commander data returned"; + /* Federation rank. [stats.py] */ "Cadet" = "Cadet"; diff --git a/companion.py b/companion.py index b75d39ae..ba8faf1a 100644 --- a/companion.py +++ b/companion.py @@ -532,6 +532,10 @@ class Session(object): def station(self) -> CAPIData: """Perform CAPI /profile endpoint query for station data.""" data = self.query(URL_QUERY) + if 'commander' not in data: + logger.error('No commander in returned data') + return data + if not data['commander'].get('docked'): return data From 5d39dee900eed0d3676bd96c1cdb2e1f8908dfef Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sat, 6 Mar 2021 10:54:15 +0000 Subject: [PATCH 3/3] CAPI: Log if no commander in profile() data --- companion.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/companion.py b/companion.py index ba8faf1a..850f3a7a 100644 --- a/companion.py +++ b/companion.py @@ -527,7 +527,11 @@ class Session(object): def profile(self) -> CAPIData: """Perform general CAPI /profile endpoint query.""" - return self.query(URL_QUERY) + data = self.query(URL_QUERY) + if 'commander' not in data: + logger.error('No commander in returned data') + + return data def station(self) -> CAPIData: """Perform CAPI /profile endpoint query for station data."""