Private
Public Access
1
0

not working yet - added scope to request body

This commit is contained in:
Sander Roosendaal
2016-12-21 22:41:33 +01:00
parent 1f1c06f04d
commit 29de886c87
3 changed files with 29 additions and 5 deletions

View File

@@ -24,6 +24,9 @@ import pandas as pd
import numpy as np import numpy as np
from rowers.models import Rower,Workout from rowers.models import Rower,Workout
import sys import sys
import urllib
from requests import Request, Session
from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET
@@ -233,6 +236,7 @@ def createc2workoutdata(w):
return data return data
def do_refresh_token(refreshtoken): def do_refresh_token(refreshtoken):
scope = "results:write,user:read"
client_auth = requests.auth.HTTPBasicAuth(C2_CLIENT_ID, C2_CLIENT_SECRET) client_auth = requests.auth.HTTPBasicAuth(C2_CLIENT_ID, C2_CLIENT_SECRET)
post_data = {"grant_type": "refresh_token", post_data = {"grant_type": "refresh_token",
"client_secret": C2_CLIENT_SECRET, "client_secret": C2_CLIENT_SECRET,
@@ -240,10 +244,25 @@ def do_refresh_token(refreshtoken):
"refresh_token": refreshtoken, "refresh_token": refreshtoken,
} }
headers = {'user-agent': 'sanderroosendaal'} headers = {'user-agent': 'sanderroosendaal'}
response = requests.post("https://log.concept2.com/oauth/access_token", url = "https://log.concept2.com/oauth/access_token"
data=post_data, s = Session()
headers=headers) req = Request('POST',url, data=post_data, headers=headers)
# response = requests.post("https://log.concept2.com/oauth/access_token",
# data=post_data,
# data=post_data,
# headers=headers)
prepped = req.prepare()
print prepped.body
prepped.body+="&scope="
prepped.body+=scope
print prepped.body
response = s.send(prepped)
print response.status_code
print response
token_json = response.json() token_json = response.json()
try: try:
thetoken = token_json['access_token'] thetoken = token_json['access_token']
@@ -263,9 +282,11 @@ def do_refresh_token(refreshtoken):
def get_token(code): def get_token(code):
scope = "user:read,results:write"
client_auth = requests.auth.HTTPBasicAuth(C2_CLIENT_ID, C2_CLIENT_SECRET) client_auth = requests.auth.HTTPBasicAuth(C2_CLIENT_ID, C2_CLIENT_SECRET)
post_data = {"grant_type": "authorization_code", post_data = {"grant_type": "authorization_code",
"code": code, "code": code,
"scope": scope,
"redirect_uri": C2_REDIRECT_URI, "redirect_uri": C2_REDIRECT_URI,
"client_secret": C2_CLIENT_SECRET, "client_secret": C2_CLIENT_SECRET,
"client_id":C2_CLIENT_ID, "client_id":C2_CLIENT_ID,
@@ -286,11 +307,12 @@ def make_authorization_url(request):
# Save it for use later to prevent xsrf attacks # Save it for use later to prevent xsrf attacks
from uuid import uuid4 from uuid import uuid4
state = str(uuid4()) state = str(uuid4())
scope = "user:read,results:write"
params = {"client_id": CLIENT_ID, params = {"client_id": CLIENT_ID,
"response_type": "code", "response_type": "code",
"scope":scope,
"redirect_uri": REDIRECT_URI} "redirect_uri": REDIRECT_URI}
import urllib
url = "https://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params) url = "https://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params)
# url = "https://ssl.reddit.com/api/v1/authorize?" + urllib.urlencode(params) # url = "https://ssl.reddit.com/api/v1/authorize?" + urllib.urlencode(params)

View File

@@ -518,7 +518,7 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True,
try: try:
drivespeed = drivelength/rowdatadf[' DriveTime (ms)']*1.0e3 drivespeed = drivelength/rowdatadf[' DriveTime (ms)']*1.0e3
except TypeError: except TypeError:
drivespeed = 0.0*drivelength drivespeed = 0.0*rowdatadf['TimeStam (sec)']
drivespeed = drivespeed.fillna(value=0) drivespeed = drivespeed.fillna(value=0)
driveenergy = drivelength*averageforce*4.44822 driveenergy = drivelength*averageforce*4.44822

View File

@@ -1095,9 +1095,11 @@ def rower_c2_authorize(request):
# Save it for use later to prevent xsrf attacks # Save it for use later to prevent xsrf attacks
from uuid import uuid4 from uuid import uuid4
state = str(uuid4()) state = str(uuid4())
scope = "user:read,results:write"
params = {"client_id": C2_CLIENT_ID, params = {"client_id": C2_CLIENT_ID,
"response_type": "code", "response_type": "code",
"scope":scope,
"redirect_uri": C2_REDIRECT_URI} "redirect_uri": C2_REDIRECT_URI}
import urllib import urllib
url = "http://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params) url = "http://log.concept2.com/oauth/authorize?"+ urllib.urlencode(params)