Update oauth access token expiration time

main
Georg Krause 2022-02-05 11:12:48 +01:00
parent 228535e042
commit 0c4908e9b6
No known key found for this signature in database
GPG Key ID: FD479B9A4D48E632
1 changed files with 7 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import logging
import os
import requests
import requests_oauthlib
from datetime import datetime
from mopidy import httpclient, exceptions
@ -147,17 +148,19 @@ def get_token(config):
except IOError:
return None
try:
return json.loads(raw)
token_data = json.loads(raw)
token_data["expires_in"] = token_data["expires_at"] - datetime.timestamp(datetime.now())
return token_data
except (TypeError, ValueError):
logger.error("Cannot decode token data, you may need to relogin")
def set_token(token_data, config):
import mopidy_funkwhale
expires_in = token_data["expires_at"] - datetime.timestamp(datetime.now())
token_data["expires_in"] = expires_in
data_dir = mopidy_funkwhale.Extension.get_data_dir(config)
print(data_dir)
content = json.dumps(token_data)