mirror of
https://github.com/Dielee/volvo2mqtt.git
synced 2026-08-13 11:19:52 +02:00
Fix missing refresh token from reauth
This commit is contained in:
+16
-5
@@ -191,16 +191,27 @@ def refresh_auth():
|
|||||||
|
|
||||||
if auth.status_code == 200:
|
if auth.status_code == 200:
|
||||||
token_path = util.get_token_path()
|
token_path = util.get_token_path()
|
||||||
data = auth.json()
|
refresh_data = auth.json()
|
||||||
util.save_to_json(data, token_path)
|
|
||||||
session.headers.update({"authorization": "Bearer " + data["access_token"]})
|
f = open(token_path)
|
||||||
|
try:
|
||||||
|
data = json.load(f)
|
||||||
|
refresh_token = data["refresh_token"]
|
||||||
|
except ValueError:
|
||||||
|
raise Exception("Cannot refresh token!")
|
||||||
|
|
||||||
|
refresh_data["refresh_token"] = refresh_token
|
||||||
|
util.save_to_json(refresh_data, token_path)
|
||||||
|
session.headers.update({"authorization": "Bearer " + refresh_data["access_token"]})
|
||||||
|
|
||||||
global token_expires_at
|
global token_expires_at
|
||||||
token_expires_at = datetime.now(util.TZ) + timedelta(seconds=(data["expires_in"] - 30))
|
token_expires_at = datetime.now(util.TZ) + timedelta(seconds=(refresh_data["expires_in"] - 30))
|
||||||
refresh_token = data["refresh_token"]
|
refresh_token = refresh_data["refresh_token"]
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
logging.warning("Refreshing credentials failed!: " + str(auth.status_code) + " Message: " + auth.text)
|
logging.warning("Refreshing credentials failed!: " + str(auth.status_code) + " Message: " + auth.text)
|
||||||
authorize(renew_tokenfile=True)
|
authorize(renew_tokenfile=True)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_vehicles():
|
def get_vehicles():
|
||||||
|
|||||||
Reference in New Issue
Block a user