Private
Public Access
1
0

mocking c2import successfully

This commit is contained in:
Sander Roosendaal
2018-07-01 13:23:24 +02:00
parent e8dd12c8b8
commit cbaada7945
11 changed files with 1804 additions and 57 deletions

View File

@@ -48,40 +48,17 @@ oauth_data = {
# Exchange access code for long-lived access token
def get_token(code):
client_auth = requests.auth.HTTPBasicAuth(STRAVA_CLIENT_ID, STRAVA_CLIENT_SECRET)
post_data = {"grant_type": "authorization_code",
"code": code,
"redirect_uri": STRAVA_REDIRECT_URI,
"client_secret": STRAVA_CLIENT_SECRET,
"client_id":STRAVA_CLIENT_ID,
}
headers = {'user-agent': 'sanderroosendaal'}
response = requests.post("https://www.strava.com/oauth/token",
data=post_data,
headers=headers)
try:
token_json = response.json()
thetoken = token_json['access_token']
except (KeyError,JSONDecodeError):
thetoken = 0
(
thetoken, expires_in, refresh_token
) = imports_get_token(code, oauth_data)
return [thetoken]
# Make authorization URL including random string
def make_authorization_url(request):
# Generate a random string for the state parameter
# Save it for use later to prevent xsrf attacks
state = str(uuid4())
params = {"client_id": STRAVA_CLIENT_ID,
"response_type": "code",
"redirect_uri": STRAVA_REDIRECT_URI,
"scope":"write"}
import urllib
url = "https://www.strava.com/oauth/authorize" +urllib.urlencode(params)
return HttpResponseRedirect(url)
return imports_make_authorization_url(oauth_data)
# Get list of workouts available on Strava
def get_strava_workout_list(user,limit_n=0):