-
-
Notifications
You must be signed in to change notification settings - Fork 424
Description
I'm building an api integration, and I can get it working using plain requests yet not with requests-oauthlib. The traceback goes to the oauthlib itself, but this is similar to unsolved issue 286 on this repo, so I'll post here for now.
The api I'm hitting isn't public, so I'll do my best to provide context even if you can't directly reproduce.
Here's what works with requests. This is at the callback stage, and the state is definitely the same state from the authorization url:
access_url = access_token_url + '?grant_type=authorization_code' + '&code=' + request.GET.get('code', '') + '&client_id=' + my_client_id + '&redirect_uri=' + redirect_uri + '&client_secret=' + client_secret + '&state=' + request.session['oauth_state']
token = requests.post(access_url)
Here's what fails with requests-oauthlib:
myobject = OAuth2Session(client_id = client_id, redirect_uri = redirect_uri, state = request.session['oauth_state'])
token = myobject.fetch_token(access_token_url, authorization_response=request.build_absolute_uri(), client_secret=client_secret
I'm fairly sure that the request.build_absolute_uri() is not the problem, because that part works for other API integrations; that most certainly returns the full url it needs to parse.
Anyways here's the error traceback:
File "/app/.heroku/python/lib/python3.6/site-packages/requests_oauthlib/oauth2_session.py" in fetch_token
244. self._client.parse_request_body_response(r.text, scope=self.scope)
File "/app/.heroku/python/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/clients/base.py" in parse_request_body_response
411. self.token = parse_token_response(body, scope=scope)
File "/app/.heroku/python/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py" in parse_token_response
379. validate_token_parameters(params)
File "/app/.heroku/python/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py" in validate_token_parameters
389. raise MissingTokenError(description="Missing access token parameter.")
So, somehow oauthlib raises an error because it can't find the access token parameter when it tries to validate whether parse_token_response() worked. So something seems to be going wrong at parse_token_response().
And this is what the token looks like when we do obtain the token:
{
"access_token": “<access_token>”,
"expires_in": 36000.0,
"refresh_token”: “<refresh_token>”
}
If someone can tell me how to inspect exactly what raw http requests are being sent by object.fetch_token(), that would also help me diagnose further. Is there a way to inspect the oauth2session object to find that, or does anyone happen to know an easy way to find that for a django app on heroku? (it's not in heroku logs)
Thanks for contributing to such an elegant package. The overall quality really makes me want to fix this rather than use the plain old requests code in my app.