Skip to content

Commit

Permalink
fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
idreamshen committed May 11, 2024
1 parent 9951e97 commit ff456ca
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions custom_components/volvooncall_cn/volvooncall_cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(self, session, username, password):

self._refresh_token = ""
self._digitalvolvo_access_token = ""
self._digitalvolvo_x_token = ""
self._vocapi_access_token = ""
self._access_token_expire_at = 0

Expand Down Expand Up @@ -111,6 +112,9 @@ async def _request_digitalvolvo(self, method, url, headers, **kwargs):
if self._digitalvolvo_access_token:
final_headers["authorization"] = "Bearer " + self._digitalvolvo_access_token

if self._digitalvolvo_x_token:
final_headers["X-Token"] = self._digitalvolvo_x_token

sign = sign_request(url, method, kwargs.get('body', None))
final_headers["x-sdk-date"] = sign['x-sdk-date']
final_headers["v587sign"] = sign['v587sign']
Expand Down Expand Up @@ -181,6 +185,7 @@ async def login(self):
self._refresh_token = result["data"]["refreshToken"]
self._vocapi_access_token = result["data"]["globalAccessToken"]
self._digitalvolvo_access_token = result["data"]["accessToken"]
self._digitalvolvo_x_token = result["data"]["jwtToken"]
now = int(time.time())
self._access_token_expire_at = now + int(result["data"]["expiresIn"])

Expand All @@ -196,6 +201,7 @@ async def update_token(self):
self._refresh_token = result["data"]["refreshToken"]
self._vocapi_access_token = result["data"]["globalAccessToken"]
self._digitalvolvo_access_token = result["data"]["accessToken"]
self._digitalvolvo_x_token = result["data"]["jwtToken"]
self._access_token_expire_at = now + int(result["data"]["expiresIn"])

async def get_vehicles(self):
Expand Down Expand Up @@ -474,7 +480,7 @@ def sign_request(url, method, body):
"x-sdk-content-sha256": "UNSIGNED-PAYLOAD",
"host": "apigateway.digitalvolvo.com"
},
'method': "POST",
'method': method,
'body': body,
'uri': parsed_url.path,
'host': "apigateway.digitalvolvo.com",
Expand All @@ -496,7 +502,7 @@ def sign_request(url, method, body):

return {
'x-sdk-date': request['headers']['x-sdk-date'],
'v587sign': format_auth_header(signature, key, [k.lower() for k in request['headers']])
'v587sign': format_auth_header(signature, key, sorted([k.lower() for k in request['headers']]))
}

async def main():
Expand Down

0 comments on commit ff456ca

Please sign in to comment.