-
-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing access Token parameter with OAuth2Session, but plain ol' requests works. #324
Comments
@realimpat I had the exact same problem. Wasn't a public API, so I couldn't publish the details of how I was calling it, and couldn't reproduce it without having to build my own webapp. I tried running it with pdb turned on, and the refresh token in my case was definitely present in the response from the web server, just not be stored within the auth object that was exposed to me at the end. I was never able to pin down exactly where in the flow the refresh token wasn't getting passed / saved. |
@singingwolfboy I had this problem too with a private API. The fetch_token call was returning a 401 and not generating a token. I spoke with my API provider, and it turns out they require everything be passed in the url querystring, but there doesn't seem to be an option for that in the fetch_token method. Is this accurate? If so, can you add an option to pass params into the fetch_token method? When I changed your oauth2_session.py fetch_token from self.post(data=dict(urldecode(body), ...) to self.post(params=dict(urldecode(body), ...), it worked. I also made a pull request in case that's easiest for you. Thanks for this fantastic package! |
Has this been fixed at all? client = LegacyApplicationClient(client_id=client_id) This gives me the error:
|
@datacubed Same thing. But I get the |
My colleague grissman submitted a pull request that fixed this issue for
us. I don't think it has been merged yet.
Essentially what was happening (at least in our case) is that the API
provider only accepted parameters through the url querystring. For some
reason, OAuthlib only accepts parameters through headers. So we modified
the OAuthlib source code to allow an option to toggle if you need to do
things through the urls instead of via headers.
The code works, so if you can view that PR you can implement it locally if
you need in the meantime.
…On Fri, Oct 5, 2018 at 3:37 PM João Meyer ***@***.***> wrote:
@datacubed <https://github.com/datacubed> Same thing. But I get the
invalid_grant error from the server. But using the old requests module
works fine.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#324 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AhMFp82F79iACYrN4KvcXhJLWFhuAtGbks5uh8LwgaJpZM4V3eVv>
.
|
I had the same problem, but it went away when I put a trailing slash '/' on the token_url. That has nothing to do with the requests-oauthlib library -- it was a django rest server and the oauth2 token url routes needed that trailing slash. YMMV |
oauthlib.oauth2.rfc6749.errors.MissingTokenError Traceback (most recent call last)
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter. how to solve this,plz anybody help me. |
Any updates to this? I'm having similar problems as OP when trying to access Withings API. Weird enough, Google API seems to be working as expected tho.
|
same for me with withings api :-/ |
Getting the same err: MissingTokenError: (missing_token) Missing access token parameter. |
I downgraded the requests-oauthlib library and now my requests with python-nokia are fine again.. |
I got this same experience with Intercom OAuth; I added |
I noticed that if your code don't set a scope for your OAuth request, you get this error. I was using the "Backend Application Flow" as documented - https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow And it didn't work because of an error in the documentation which says
And should say something like
|
I was also hitting this even following all the above recommendations (beside downgrading) and this commit from another project got me on the right track. Basically I was hitting the wrong endpoint path but from the Traceback it was almost impossible to tell. I leave the details here for the records: def get_oauth_token(client_id, client_secret, token_url):
"""https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html"""
scope = ['hello','world']
from oauthlib.oauth2 import BackendApplicationClient
client = BackendApplicationClient(client_id=client_id, scope=scope)
from requests_oauthlib import OAuth2Session
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=token_url,
client_id=client_id,
client_secret=client_secret,
include_client_id=True)
return token Traceback (most recent call last):
File "[...]lambda_utils.py", line 130, in <module>
"[...url...]",
File "[...]lambda_utils.py", line 122, in get_oauth_token
include_client_id=True)
File "[...]requests_oauthlib/oauth2_session.py", line 360, in fetch_token
self._client.parse_request_body_response(r.text, scope=self.scope)
File "[...]oauthlib/oauth2/rfc6749/clients/base.py", line 421, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "[...]oauthlib/oauth2/rfc6749/parameters.py", line 431, in parse_token_response
validate_token_parameters(params)
File "[...]oauthlib/oauth2/rfc6749/parameters.py", line 441, in validate_token_parameters
raise MissingTokenError(description="Missing access token parameter.")
oauthlib.oauth2.rfc6749.errors.MissingTokenError: (missing_token) Missing access token parameter. Testing this on macOS 10.14.6: $ python
Python 3.7.6 (default, Jan 18 2020, 11:17:36)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import oauthlib
>>> import requests_oauthlib
>>> oauthlib.__version__, requests_oauthlib.__version__
('3.1.0', '1.3.0') |
I was having the same error... and in my case, the URL I was using was wrong. :-) I had "oauth2/token" when in my case it should have been "oauth/token" Example cut and pasted from the readthedocs.io works, after my custom changes as above. |
@calcium unfortunately I've forgot about the circumstances of this issue, it might be I was facing the same error as yours (wrong URL), thanks for pointing it out |
I am having the same error message: I am curious what file you @calcium are editing when you say "I had "oauth2/token" when in my case it should have been "oauth/token"" ? |
This happened to me and the problem was in the response, it was lacking the expected JSON structure consisting of an object with the key |
The following should apply to most cases but I figure I'll add my specifics first. I'm trying to make a request with a token I know is expired (needs to be refreshed). I'm using the "3rd" option for refreshing outlined here: https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#refreshing-tokens My calling code looks like:
So, when a call gets made, if the token is expired,
But client secret and client_id would need to be passed in via Anyway, much of this may be specific to my case, but here's the generic part. In the refresh call, there is this line:
Calling this line throws the missing access token error. I think the correct way of interpreting this error, in my case, is not that I did not pass in an access token (what I originally thought), but that the response from the server did not contain an access token! So what happened in my case? (and how might this help you) The error is coming from oauthlib:
So, I wanted to see what exactly was missing, and changed this code to:
Basically I've just enabled debugging. Feel free to use your own debugging approach. In debugging I can now look at the value of params, which is:
So basically fitbit threw a bunch of json back at us saying my request was bad because there was no authorization. OK, so I still don't know how to fix that, but at least I know what the general problem is. So in summary, this error can be triggered when the response from the server is missing an access token parameter, not necessarily that your call is missing an access token (Note, if you're trying to get an access token and not a refresh token, this may be more obvious to you since you don't already have an access token). Unfortunately, errors from the server are being swallowed by requests-oauthlib and/or oauthlib? such that instead of the error message from the server (with potentially more relevant details), you only are told that the access token is missing (i.e. "something went wrong and we're not sure what"). Note, I haven't dissected this call more:
But it seems like it may be a good idea if either this was wrapped in a try-except statement, or the status code from the refresh call (or access call) was inspected, or perhaps both ... and again, I don't know how to fix my code, but I'm off to SO to follow up (someone previously asked this question) Hopefully this helps ... |
This solution worked for Teamwork API, thanks |
Hi, Everyone. `Linux 20.04.1-Ubuntu 2021 x86_64 x86_64 x86_64 GNU/Linux $ python --version I am trying to use the module "requests_oauthlib" (pip install requests_oauthlib) raise MissingTokenError(description="Missing access token parameter.") To investigate this issue, I did the example from Backend Application Flow
Does not work. I am also using the module icecream for debug: pip install icecream
to reproduce the issue: the source code
Someone have an idea of how to fix this, Thanks in advance, cheers. Andre |
Work in progress. following the traceback Error: I found this:
-> params does not have 'access_token' and the variable params in the So, maybe the class OAuth2Token does not return the acess_token : hash commit Hi @ib-lundgren can you help me in this issue? I hope this description can help you. Thank you very much! |
I guess these issues may be related to #302 . |
If this helps anyone, I had to make requests against a {'Server': 'Microsoft-Azure-Application-Gateway/v2'} server which apparently have some sort of sick WAF setting. Adding the following to fetch_token() fixed my problem.
|
interesting that our of all, this comment by @adyekjaer worked for me. Thanks |
I had a similar issue with using the incorrect token url, if you open up
Add the line This should help you debug the issue. |
I encountered this issue, and the resolution was to add
The clue was in the source file here https://github.com/requests/requests-oauthlib/blob/master/requests_oauthlib/oauth2_session.py |
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:
Here's what fails with requests-oauthlib:
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:
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:
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.
The text was updated successfully, but these errors were encountered: