-
Notifications
You must be signed in to change notification settings - Fork 1
/
refreshTokens.py
26 lines (25 loc) · 901 Bytes
/
refreshTokens.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests
import time
import databaseAccess
import os
client_id = os.environ.get('CLIENTID')
client_secret = os.environ.get('CLIENTSECRET')
strava_tokens = databaseAccess.getConfig()
if strava_tokens['expires_at'] < time.time():
try:
response = requests.post(
url='https://www.strava.com/oauth/token',
data={
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'refresh_token',
'refresh_token': strava_tokens['refresh_token']
},
timeout=10 # 10 seconds timeout
)
new_strava_tokens = response.json()
databaseAccess.setConfig(strava_tokens)
# Use new Strava tokens from now
strava_tokens = new_strava_tokens
except requests.exceptions.Timeout:
print("Timeout occurred while refreshing Strava tokens")