Skip to content

Commit

Permalink
Add pin request preflight changes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneNulschDE committed Feb 6, 2024
1 parent 0e8b4a9 commit b0c93b4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion custom_components/mbapi2020/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ def __init__(
STORAGE_DIR, f"{TOKEN_FILE_PREFIX}-{config_entry.entry_id}"
)
self.token = None
self._xsessionid = ""

async def request_pin(self, email: str, nonce: str):
"""Initiate a PIN request."""
_LOGGER.info("Start request PIN %s", email)
_LOGGER.info("PIN preflight request 1")
headers = self._get_header()
url = f"{helper.Rest_url(self._region)}/v1/config"
r = await self._async_request("get", url, headers=headers)

_LOGGER.info("PIN request")
url = f"{helper.Rest_url(self._region)}/v1/login"
data = f'{{"emailOrPhoneNumber" : "{email}", "countryCode" : "{DEFAULT_COUNTRY_CODE}", "nonce" : "{nonce}"}}'
headers = self._get_header()
Expand Down Expand Up @@ -209,13 +216,16 @@ def _add_custom_values_to_token_info(cls, token_info):
return token_info

def _get_header(self):
if not self._xsessionid:
self._xsessionid = str(uuid.uuid4())

header = {
"Ris-Os-Name": RIS_OS_NAME,
"Ris-Os-Version": RIS_OS_VERSION,
"Ris-Sdk-Version": RIS_SDK_VERSION,
"X-Locale": DEFAULT_LOCALE,
"X-Trackingid": str(uuid.uuid4()),
"X-Sessionid": str(uuid.uuid4()),
"X-Sessionid": self._xsessionid,
"User-Agent": WEBSOCKET_USER_AGENT,
"Content-Type": "application/json",
"Accept-Language": "en-GB",
Expand Down

0 comments on commit b0c93b4

Please sign in to comment.