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