From b00176c21934eef9fabedff2d4dc984a50ffd764 Mon Sep 17 00:00:00 2001 From: rikroe Date: Wed, 21 Oct 2020 23:43:07 +0200 Subject: [PATCH] Fix rest_of_world login --- bimmer_connected/account.py | 29 +++++++---------------------- bimmer_connected/const.py | 2 +- test/test_state.py | 3 +-- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/bimmer_connected/account.py b/bimmer_connected/account.py index 5377771b..fe04a9d0 100644 --- a/bimmer_connected/account.py +++ b/bimmer_connected/account.py @@ -72,38 +72,28 @@ def _get_oauth_token(self) -> None: "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "124", "Connection": "Keep-Alive", - "Host": self.server_url, + "Host": "customer.bmwgroup.com" if self._region == Regions.REST_OF_WORLD else self.server_url, "Accept-Encoding": "gzip", - "Authorization": "Basic blF2NkNxdHhKdVhXUDc0eGYzQ0p3VUVQOjF6REh4NnVuNGNEanli" - "TEVOTjNreWZ1bVgya0VZaWdXUGNRcGR2RFJwSUJrN3JPSg==", + "Authorization": "Basic ZDc2NmI1MzctYTY1NC00Y2JkLWEzZGMtMGNhNTY3MmQ3ZjhkOjE1" + "ZjY5N2Y2LWE1ZDUtNGNhZC05OWQ5LTNhMTViYzdmMzk3Mw==", "Credentials": "nQv6CqtxJuXWP74xf3CJwUEP:1zDHx6un4cDjybLENN3kyfumX2kEYigWPcQpdvDRpIBk7rOJ", - "User-Agent": "okhttp/2.60", + "User-Agent": "okhttp/3.12.2", } # we really need all of these parameters values = { 'scope': 'authenticate_user vehicle_data remote_services', + 'grant_type': 'password', 'username': self._username, 'password': self._password, } - if self._region == Regions.REST_OF_WORLD: - values.update({ - 'client_id': 'dbf0a542-ebd1-4ff0-a9a7-55172fbfce35', - 'response_type': 'token', - 'redirect_uri': 'https://www.bmw-connecteddrive.com/app/static/external-dispatch.html', - }) - else: - values.update({ - 'grant_type': 'password', - }) - data = urllib.parse.urlencode(values) if self._region == Regions.REST_OF_WORLD: url = AUTH_URL.format( gcdm_oauth_endpoint=get_gcdm_oauth_endpoint(self._region) ) - expected_response_code = 302 + expected_response_code = 200 else: url = AUTH_URL_LEGACY.format(server=self.server_url) expected_response_code = 200 @@ -116,12 +106,7 @@ def _get_oauth_token(self) -> None: _LOGGER.exception(exception) raise OSError(msg) from exception - if self._region == Regions.REST_OF_WORLD: - response_json = dict( - urllib.parse.parse_qsl(urllib.parse.urlparse(response.headers['Location']).fragment) - ) - else: - response_json = response.json() + response_json = response.json() self._oauth_token = response_json['access_token'] expiration_time = int(response_json['expires_in']) diff --git a/bimmer_connected/const.py b/bimmer_connected/const.py index 4dcf4cf1..b5cb3225 100644 --- a/bimmer_connected/const.py +++ b/bimmer_connected/const.py @@ -1,6 +1,6 @@ """URLs for different services and error code mapping.""" -AUTH_URL = 'https://customer.bmwgroup.com/{gcdm_oauth_endpoint}/authenticate' +AUTH_URL = 'https://customer.bmwgroup.com/{gcdm_oauth_endpoint}/token' AUTH_URL_LEGACY = 'https://{server}/gcdm/oauth/token' BASE_URL = 'https://{server}/webapi/v1' diff --git a/test/test_state.py b/test/test_state.py index b2b02f84..c879872d 100644 --- a/test/test_state.py +++ b/test/test_state.py @@ -144,8 +144,7 @@ def test_update_data(self): with mock.patch('bimmer_connected.account.requests', new=backend_mock): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_REGION) vehicle = account.get_vehicle(G31_VIN) - with self.assertRaises(IOError): - vehicle.state.update_data() + vehicle.state.update_data() backend_mock.setup_default_vehicles()