From 2218c570fb35b26a962cfff8287ac66d126fe3ab Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Thu, 25 Feb 2021 00:19:41 -0800 Subject: [PATCH 1/5] feat: allow reset of proxy --- teslajsonpy/teslaproxy.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/teslajsonpy/teslaproxy.py b/teslajsonpy/teslaproxy.py index 46937a85..7eb33825 100644 --- a/teslajsonpy/teslaproxy.py +++ b/teslajsonpy/teslaproxy.py @@ -130,6 +130,14 @@ async def prepend_relative_urls(self, base_url: URL, html: Text) -> Text: html=html, ) + async def reset_data(self) -> None: + """Reset all stored data. + + A proxy may need to service multiple login requests if the route is not torn down. This function will reset all data between logins. + """ + self.waf_retry = 0 + await super().reset_data() + async def prepend_i18n_path(self, base_url: URL, html: Text) -> Text: """Prepend path for i18n loadPath so it'll reach the proxy. From 37207cea14b19d7961f2d6f774d2ba4ffadce043 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Thu, 25 Feb 2021 00:21:20 -0800 Subject: [PATCH 2/5] fix: catch code even without redirect --- teslajsonpy/teslaproxy.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/teslajsonpy/teslaproxy.py b/teslajsonpy/teslaproxy.py index 7eb33825..07685092 100644 --- a/teslajsonpy/teslaproxy.py +++ b/teslajsonpy/teslaproxy.py @@ -78,17 +78,19 @@ async def test_url( Optional[Union[URL, Text]]: URL for a http 302 redirect or Text to display on success. None indicates test did not pass. """ - - if str(resp.url) == "https://auth.tesla.com/static/404.html": + code: Text = "" + if resp.url.path == "/void/callback": + code = resp.url.query.get("code") + if resp.url.path == "/static/404.html": code = URL(resp.history[-1].url).query.get("code") + if code: username = data.get("identity") self._callback_url = self.init_query.get("callback_url") - if code: - _LOGGER.debug("Success! Oauth code %s for %s captured.", code, username) - # 302 redirect - return URL(self._callback_url).update_query( - {"code": code, "username": username} - ) + _LOGGER.debug("Success! Oauth code %s for %s captured.", code, username) + # 302 redirect + return URL(self._callback_url).update_query( + {"code": code, "username": username} + ) if resp.content_type == "text/html": text = await resp.text() if "