Disable the integrity header as it's not needed

This commit is contained in:
DevilXD committed 2022-10-23 11:58:31 +02:00
1 parent 2881cf0ad5
commit a9d331e1b7
1 file changed
+30 -32
+30 -32
View File
@@ -1,13 +1,13 @@
from __future__ import annotations from __future__ import annotations
import re import re
import json # import json
import asyncio import asyncio
import logging import logging
from math import ceil from math import ceil
from time import time from time import time
from functools import partial from functools import partial
from base64 import urlsafe_b64decode # from base64 import urlsafe_b64decode
from collections import abc, OrderedDict from collections import abc, OrderedDict
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from contextlib import suppress, asynccontextmanager from contextlib import suppress, asynccontextmanager
@@ -200,8 +200,8 @@ class _AuthState:
"Client-Version": self.client_version, "Client-Version": self.client_version,
"X-Device-Id": self.device_id, "X-Device-Id": self.device_id,
} }
if integrity: # if integrity:
headers["Client-Integrity"] = self.integrity_token # headers["Client-Integrity"] = self.integrity_token
return headers return headers
async def validate(self): async def validate(self):
@@ -261,33 +261,31 @@ class _AuthState:
# update our cookie and save it # update our cookie and save it
jar.update_cookies(cookie, BASE_URL) jar.update_cookies(cookie, BASE_URL)
jar.save(COOKIES_PATH) jar.save(COOKIES_PATH)
if not self._hasattrs("integrity_token") or self.integrity_expired: # if not self._hasattrs("integrity_token") or self.integrity_expired:
async with self._twitch.request( # async with self._twitch.request(
"POST", # "POST",
"https://gql.twitch.tv/integrity", # "https://gql.twitch.tv/integrity",
headers=self.gql_headers(integrity=False) # headers=self.gql_headers(integrity=False)
) as response: # ) as response:
self._last_request = datetime.now(timezone.utc) # self._last_request = datetime.now(timezone.utc)
response_json: JsonType = await response.json() # response_json: JsonType = await response.json()
self.integrity_token = cast(str, response_json["token"]) # self.integrity_token = cast(str, response_json["token"])
# (i = Math.round(.9 * (n.expiration - Date.now()))) < 0 # now = datetime.now(timezone.utc)
# || (this.logger.debug("Refreshing in ".concat(Math.round(i / 1e3 / 60), " minutes")) # expiration = datetime.fromtimestamp(response_json["expiration"] / 1000, timezone.utc)
now = datetime.now(timezone.utc) # self.integrity_expires = ((expiration - now) * 0.9) + now
expiration = datetime.fromtimestamp(response_json["expiration"] / 1000, timezone.utc) # # verify the integrity token's contents for the "is_bad_bot" flag
self.integrity_expires = ((expiration - now) * 0.9) + now # stripped_token: str = self.integrity_token.split('.')[2] + "=="
# verify the integrity token's contents for the "is_bad_bot" flag # messy_json: str = urlsafe_b64decode(stripped_token.encode()).decode(errors="ignore")
stripped_token: str = self.integrity_token.split('.')[2] + "==" # match = re.search(r'(.+)(?<="}).+$', messy_json)
messy_json: str = urlsafe_b64decode(stripped_token.encode()).decode(errors="ignore") # if match is None:
match = re.search(r'(.+)(?<="}).+$', messy_json) # raise MinerException("Unable to parse the integrity token")
if match is None: # decoded_header: JsonType = json.loads(match.group(1))
raise MinerException("Unable to parse the integrity token") # if decoded_header.get("is_bad_bot", "false") != "false":
decoded_header: JsonType = json.loads(match.group(1)) # self._twitch.print(
if decoded_header.get("is_bad_bot", "false") != "false": # "Twitch has detected this miner as a \"Bad Bot\". "
self._twitch.print( # "You're proceeding at your own risk!"
"Twitch has detected this miner as a \"Bad Bot\". " # )
"You're proceeding at your own risk!" # await asyncio.sleep(8)
)
await asyncio.sleep(8)
self._logged_in.set() self._logged_in.set()
def invalidate(self, *, auth: bool = False, integrity: bool = False): def invalidate(self, *, auth: bool = False, integrity: bool = False):
@@ -1051,7 +1049,7 @@ class Twitch:
"https://gql.twitch.tv/gql", "https://gql.twitch.tv/gql",
json=op, json=op,
headers=auth_state.gql_headers(integrity=True), headers=auth_state.gql_headers(integrity=True),
invalidate_after=auth_state.integrity_expires, invalidate_after=getattr(auth_state, "integrity_expires", None),
) as response: ) as response:
response_json: JsonType = await response.json() response_json: JsonType = await response.json()
except RequestInvalid: except RequestInvalid: