From 94ff95a8e7c1f1b771a273303830906e7e205453 Mon Sep 17 00:00:00 2001 From: Anton Lapshin Date: Wed, 13 Oct 2021 16:40:52 +0300 Subject: [PATCH 1/3] Rework web authorization to support MFA --- betty/consts.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/betty/consts.py b/betty/consts.py index 0a88000..b94e470 100644 --- a/betty/consts.py +++ b/betty/consts.py @@ -3,6 +3,8 @@ AUTH_START_URL = r"https://bethesda.net/en/dashboard?cogs_modal=login" AUTH_FINISH_URL = r"cogs_modal" AUTH_REDIRECT_URL = r"radiant/v1/graphql" +AUTH_CHECK_URL = r"https://api.bethesda.net/dwemer/attunement/v1/authenticate" +API_URL = r"https://api.bethesda.net" BETTY_WINREG_LOCATION = "SOFTWARE\\Bethesda Softworks\\Bethesda.net" BETTY_LAUNCHER_EXE = "BethesdaNetLauncher.exe" @@ -25,19 +27,32 @@ def regex_pattern(regex): JS = { regex_pattern(AUTH_FINISH_URL): [ r''' - function getCookie(name) { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(';').shift(); + function checkLogin() { + makeLoginRequest(() => { location.href = '%s'; }) } - function check_login() { - if (getCookie('bnet-username')) { - location.href = '%s'; + function makeLoginRequest(callback) { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == XMLHttpRequest.DONE && xhr.status >= 200 && xhr.status < 300) { + callback(); + } } + xhr.open('PUT', '%s', true); + xhr.withCredentials = true; + xhr.send(null); } - setInterval(check_login, 3000); + // Catch all requests and check if auth is successful after any API request + var origOpen = XMLHttpRequest.prototype.open; + XMLHttpRequest.prototype.open = function() { + this.addEventListener('load', async function() { + if (this.responseURL.indexOf('%s') >= 0) { + checkLogin(); + } + }); + origOpen.apply(this, arguments); + }; function findpersist() { if (document.getElementsByName("persist").length < 1) { @@ -47,6 +62,6 @@ def regex_pattern(regex): } } findpersist(); - ''' % AUTH_REDIRECT_URL + ''' % (AUTH_REDIRECT_URL, AUTH_CHECK_URL, API_URL) ] } From 306fc0e6903525c4bac0b71c01a9624071ebcfaa Mon Sep 17 00:00:00 2001 From: Anton Lapshin Date: Fri, 15 Oct 2021 21:13:24 +0300 Subject: [PATCH 2/3] Update cdn.contentful.com authorization key and skip it on fail --- betty/backend.py | 2 +- betty/plugin.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/betty/backend.py b/betty/backend.py index 594057b..3b8069c 100644 --- a/betty/backend.py +++ b/betty/backend.py @@ -40,7 +40,7 @@ async def get_owned_ids(self): async def get_game_details(self, business_id): headers = { - 'Authorization': f"Bearer 26a7d8bae3b004c1847e14418567d527e337c97440ac52113306ac6861036590", + 'Authorization': f"Bearer OUFuRGfR35XVY7LML-7ITHALa_oiRoTAwQxFTrGMgz8", 'Content-Type': "application/json" } resp = await self.http_client.do_request('get', f"https://cdn.contentful.com/spaces/rporu91m20dc/environments/master/entries?skip=0&order=&include=3&content_type=productCode&locale=en&limit=100&fields.entitlementBusinessId={business_id}", headers=headers) diff --git a/betty/plugin.py b/betty/plugin.py index ceba027..ed14113 100644 --- a/betty/plugin.py +++ b/betty/plugin.py @@ -149,7 +149,11 @@ async def get_owned_games(self): product_ids = self._check_for_owned_products(owned_ids) pre_order_ids = set(owned_ids) - set(product_ids) - games_to_send.extend(await self._get_owned_pre_orders(pre_order_ids)) + try: + games_to_send.extend(await self._get_owned_pre_orders(pre_order_ids)) + except Exception as e: + log.warning(f"Unable to obtain preorders: {repr(e)}") + games_to_send.extend(self._get_owned_games()) log.info(f"Games to send (with free games): {games_to_send}") From ef60be4de9f858f772f3ffe1cb4d61b8426d4ae7 Mon Sep 17 00:00:00 2001 From: Anton Lapshin Date: Fri, 15 Oct 2021 21:13:54 +0300 Subject: [PATCH 3/3] Up version --- betty/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/betty/manifest.json b/betty/manifest.json index a67a818..60e5bc7 100644 --- a/betty/manifest.json +++ b/betty/manifest.json @@ -2,7 +2,7 @@ "name": "Galaxy Bethesda plugin", "platform": "bethesda", "guid": "cb57391f-1675-35b1-05c0-896d43bdf4f8", - "version": "0.185", + "version": "0.186", "description": "Galaxy Bethesda plugin", "author": "TouwaStar", "email": "yowosek@gmail.com.com",