Skip to content

Commit

Permalink
Refresh token before trying to login again (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarnauts committed Aug 12, 2021
1 parent bb58e06 commit f827184
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions resources/lib/vtmgo/vtmgoauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def _check_credentials_change(self):
new_hash = md5((self._username + ':' + self._password + ':' + self._loginprovider).encode('utf-8')).hexdigest()

if new_hash != old_hash:
self._save_cache()
return new_hash
return None

Expand Down Expand Up @@ -162,6 +163,10 @@ def login(self, force=False):
self._account.hash = new_hash
force = True

# If we have an (old) token, but it isn't valid anymore, refresh it.
if not force and self._account.jwt_token and not self._account.is_valid_token():
self._android_refesh()

# Use cached token if it is still valid
if force or not self._account.is_valid_token():
# Do actual login
Expand Down Expand Up @@ -196,6 +201,9 @@ def _android_login(self):
'sdkVersion': '0.13.1',
'state': 'dnRtLWdvLWFuZHJvaWQ=', # vtm-go-android
'redirect_uri': 'https://login2.vtm.be/continue',
}, headers={
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0.1; MotoG3 Build/MPIS24.107-55-2-17; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.88 Mobile Safari/537.36',
'X-Requested-With': 'be.vmma.vtm.zenderapp',
})

# Send login credentials
Expand Down Expand Up @@ -247,6 +255,20 @@ def _android_login(self):

return self._account

def _android_refesh(self):

# We can refresh our old token so it's valid again
response = util.http_post('https://lfvp-api.dpgmedia.net/vtmgo/tokens/refresh', data={
'lfvpToken': self._account.jwt_token,
})

# Get JWT from reply
self._account.jwt_token = json.loads(response.text).get('lfvpToken')

self._save_cache()

return self._account

def _web_login(self):
""" Executes a login and returns the JSON Web Token.
:rtype str
Expand Down

0 comments on commit f827184

Please sign in to comment.