Skip to content

Commit

Permalink
Fix rest_of_world login
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Oct 21, 2020
1 parent cdfbce9 commit b00176c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
29 changes: 7 additions & 22 deletions bimmer_connected/account.py
Expand Up @@ -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
Expand All @@ -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'])
Expand Down
2 changes: 1 addition & 1 deletion 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'

Expand Down
3 changes: 1 addition & 2 deletions test/test_state.py
Expand Up @@ -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()

Expand Down

0 comments on commit b00176c

Please sign in to comment.