Last active
October 16, 2018 13:34
-
-
Save willgdjones/4df43fe8978e6868b92e523b9a0b9c71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 | |
) |
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']))
Getting closer, now the error is:
{'errors': [{'title': 'The scope requested is invalid for this request', 'status': 400, 'meta': []}]}
@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
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
@willgdjones the data should be
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 thejson
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