Skip to content

Commit

Permalink
fix: catch code even without redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Feb 25, 2021
1 parent 2218c57 commit 37207ce
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions teslajsonpy/teslaproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<noscript>Please enable JavaScript to view the page content." in text:
Expand Down

0 comments on commit 37207ce

Please sign in to comment.