From 45dec971b9dbeb3a70acbd96093ca5a4777be821 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Sat, 3 Apr 2021 00:31:20 -0700 Subject: [PATCH] fix: fix china authentication --- poetry.lock | 8 ++++---- pyproject.toml | 2 +- teslajsonpy/const.py | 2 +- teslajsonpy/teslaproxy.py | 8 ++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index 06a29942..7476ec95 100644 --- a/poetry.lock +++ b/poetry.lock @@ -79,7 +79,7 @@ tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (> [[package]] name = "authcaptureproxy" -version = "0.7.1" +version = "0.8.1" description = "A Python project to create a proxy to capture authentication information from a webpage. This is useful to capture oauth login details without access to a third-party oauth." category = "main" optional = false @@ -902,7 +902,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt [metadata] lock-version = "1.1" python-versions = "^3.6.1" -content-hash = "513bb0ac499b37fc74ec071ab684b51ae9bf923ff75a665d7ce9386c3abc4bc0" +content-hash = "a68982256fa1f745e820452050efde37c3c2c3f3e26f597abfd9a8a05afe6b44" [metadata.files] aiohttp = [ @@ -969,8 +969,8 @@ attrs = [ {file = "attrs-20.3.0.tar.gz", hash = "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700"}, ] authcaptureproxy = [ - {file = "authcaptureproxy-0.7.1-py3-none-any.whl", hash = "sha256:eac7b62249e30596a931b4a5ebac7ac2cbc34027e3aba51344768181bf90a5fb"}, - {file = "authcaptureproxy-0.7.1.tar.gz", hash = "sha256:252de42cf864eb35aac5d3b20c12ad79c3f5c329e52b70b101eaceeb55b91e8b"}, + {file = "authcaptureproxy-0.8.1-py3-none-any.whl", hash = "sha256:49c049cd19652fb67011ea84b20721748ddbd0621a7cbe1fb17c90a9f7e095a6"}, + {file = "authcaptureproxy-0.8.1.tar.gz", hash = "sha256:7326ff1bf7382447d897731d991f7f03d84c3a7307fe941bfcea0b2d536ac21e"}, ] autoapi = [ {file = "autoapi-2.0.1.tar.gz", hash = "sha256:4003b17599020652d0738dc1c426d0abf2f58f8a1821f5500816043210b3d1d6"}, diff --git a/pyproject.toml b/pyproject.toml index fbff8b0f..099002d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ aiohttp = "^3.7.4" backoff = "^1.10.0" beautifulsoup4 = "^4.9.3" wrapt = "^1.12.1" -authcaptureproxy = "~=0.7.1" +authcaptureproxy = "~=0.8.1" [tool.poetry.dev-dependencies] flake8 = "^3.9.0" diff --git a/teslajsonpy/const.py b/teslajsonpy/const.py index 6fdb9445..f1915bb0 100644 --- a/teslajsonpy/const.py +++ b/teslajsonpy/const.py @@ -11,6 +11,6 @@ DRIVING_INTERVAL = 60 # interval when driving detected WEBSOCKET_TIMEOUT = 11 # time for websocket to timeout RELEASE_NOTES_URL = "https://teslascope.com/teslapedia/software/" -AUTH_DOMAIN = "https://auth.tesla.cn" +AUTH_DOMAIN = "https://auth.tesla.com" API_URL = "https://owner-api.teslamotors.com" WS_URL = "wss://streaming.vn.teslamotors.com/streaming" diff --git a/teslajsonpy/teslaproxy.py b/teslajsonpy/teslaproxy.py index f3cdb603..94e86142 100644 --- a/teslajsonpy/teslaproxy.py +++ b/teslajsonpy/teslaproxy.py @@ -15,6 +15,7 @@ from aiohttp import ClientResponse, web from authcaptureproxy import AuthCaptureProxy, return_timer_countdown_refresh_html +from authcaptureproxy.const import SKIP_AUTO_HEADERS from authcaptureproxy.examples.modifiers import find_regex_urls from authcaptureproxy.helper import prepend_url import multidict @@ -58,6 +59,7 @@ def __init__(self, proxy_url: URL, host_url: URL) -> None: }, } ) + self.redirect_filters = {"url": ["^.*/static/404.html$"]} async def test_url( self, @@ -170,6 +172,11 @@ async def modify_headers( ) -> multidict.MultiDict: """Modify headers. + Return modified headers based on site and request. To disable auto header generation, + pass in a key const.SKIP_AUTO_HEADERS with a list of keys to not generate. + + For example, to prevent User-Agent generation: {SKIP_AUTO_HEADERS : ["User-Agent"]} + Args: site (URL): URL of the next host request. request (web.Request): Proxy directed request. This will need to be changed for the actual host request. @@ -180,6 +187,7 @@ async def modify_headers( """ result = await super().modify_headers(site, request) method = request.method + result.update({SKIP_AUTO_HEADERS: ["User-Agent"]}) if ( str(site.path) == "/oauth2/v3/authorize/mfa/verify" and method == "POST"