Skip to content

Instantly share code, notes, and snippets.

@willgdjones
Last active October 16, 2018 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willgdjones/4df43fe8978e6868b92e523b9a0b9c71 to your computer and use it in GitHub Desktop.
Save willgdjones/4df43fe8978e6868b92e523b9a0b9c71 to your computer and use it in GitHub Desktop.
@app.route('/geneplaza/login', methods=['GET', 'POST'])
@login_required
def geneplaza_login():
scopes = app.config['DEFAULT_SCOPES']
redirect_uri = app.BASE_CLIENT_URL + 'geneplaza/auth'
client_id = app.config['GENEPLAZA_CLIENT_ID']
submit_url = f"https://www.geneplaza.com/api/auth?response_type=code&client_id={client_id}&redirect_uri={redirect_uri}&scope=dataset"
return redirect(submit_url)
@app.route('/geneplaza/auth', methods=['GET'])
@login_required
def geneplaza_auth():
username = current_user.get_id()
auth_code = request.args.get("authorization_code")
dataset_id = request.args.get("dataset")
redirect_uri = app.BASE_CLIENT_URL + 'geneplaza/auth'
data = {
"data": {
"type": "token",
"attributes": {
"grant_type": "authorization_code",
"scope": dataset_id,
"code": auth_code,
"redirect_uri": redirect_uri
}
}
}
from requests.auth import HTTPBasicAuth
r = requests.post(
'https://developer.geneplaza.com/token',
auth=HTTPBasicAuth(
app.config['GENEPLAZA_CLIENT_ID'],
app.config['GENEPLAZA_CLIENT_SECRET']
),
json=data
)
@rduque1
Copy link

rduque1 commented Oct 11, 2018

@willgdjones the data should be

data = {
  "data": {
         "type": "token",
         "attributes": {
         	"grant_type": "authorization_code",
         	"scope": dataset_id,
                 "code": auth_code,
		"redirect_uri": redirect_uri
         }
    }
}

And Iam not using python often enough to know it, but should you also not have to json.dump the data or you can use the json
argument instead of the data
r = requests.post('https://developer.geneplaza.com/token', headers=headers, json=data)
If you do that you can remove the header Content-Type, as it will be added automatically

@rduque1
Copy link

rduque1 commented Oct 11, 2018

I think but that's not sure neither, you can just pass an auth argument with a tuple of password and user, and it will perform automatically the basic auth:
r = requests.post('https://developer.geneplaza.com/token', headers=headers, json=data, auth=(app.config['GENEPLAZA_CLIENT_ID'], app.config['GENEPLAZA_CLIENT_SECRET']))

@willgdjones
Copy link
Author

Getting closer, now the error is:

{'errors': [{'title': 'The scope requested is invalid for this request', 'status': 400, 'meta': []}]}

@willgdjones
Copy link
Author

screen shot 2018-10-15 at 17 33 10

This is how the integration currently looks.

@rduque1
Copy link

rduque1 commented Oct 16, 2018

@willgdjones
This is my bad in the data scope should be a string "dataset"

data = {
  "data": {
         "type": "token",
         "attributes": {
         	"grant_type": "authorization_code",
         	"scope": "dataset"
                 "code": auth_code,
		"redirect_uri": redirect_uri
         }
    }
}

You need the dataset id after to access it because the id should in the path https://developer.geneplaza.com/datasets/<DATASET_ID>/files

@willgdjones
Copy link
Author

Ok makes sense, thanks! Will try that now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment