Private
Public Access
1
0

repaired TrainingPeaks

This commit is contained in:
Sander Roosendaal
2018-07-09 06:21:34 +02:00
parent 2d84fd6cd0
commit 5fed54097d
3 changed files with 33 additions and 5 deletions

View File

@@ -28,6 +28,7 @@ oauth_data = {
'redirect_uri': TP_REDIRECT_URI,
'autorization_uri': "https://oauth.trainingpeaks.com/oauth/authorize?",
'content_type': 'application/x-www-form-urlencoded',
# 'content_type': 'application/json',
'tokenname': 'tptoken',
'refreshtokenname': 'tprefreshtoken',
'expirydatename': 'tptokenexpirydate',
@@ -46,7 +47,33 @@ def do_refresh_token(refreshtoken):
# Exchange access code for long-lived access token
def get_token(code):
return imports_get_token(code, oauth_data)
client_auth = requests.auth.HTTPBasicAuth(TP_CLIENT_KEY, TP_CLIENT_SECRET)
post_data = {
"client_id":TP_CLIENT_KEY,
"grant_type": "authorization_code",
"code": code,
"redirect_uri":TP_REDIRECT_URI,
"client_secret": TP_CLIENT_SECRET,
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post("https://oauth.trainingpeaks.com/oauth/token",
data=post_data)
try:
token_json = response.json()
thetoken = token_json['access_token']
expires_in = token_json['expires_in']
refresh_token = token_json['refresh_token']
except KeyError:
thetoken = 0
expires_in = 0
refresh_token = 0
return thetoken,expires_in,refresh_token
# Make authorization URL including random string
def make_authorization_url(request):