requests-oauthlib icon indicating copy to clipboard operation
requests-oauthlib copied to clipboard

Missing code parameter while fetching token for Google

Open bdesbiolles opened this issue 7 years ago • 1 comments

Hello,

I followed the Google Oauth2 example and I managed to get the authorization code but fetching the token I have the following error:

Traceback (most recent call last): File "/home/baptiste/Code/Databerries/iap_script/user_auth.py", line 28, in authorization_response=redirect_response) File "/home/baptiste/.virtualenvs/iap_script/lib/python3.6/site-packages/requests_oauthlib/oauth2_session.py", line 187, in fetch_token state=self._state) File "/home/baptiste/.virtualenvs/iap_script/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py", line 174, in parse_request_uri_response response = parse_authorization_code_response(uri, state=state) File "/home/baptiste/.virtualenvs/iap_script/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 227, in parse_authorization_code_response raise MissingCodeError("Missing code parameter in response.") oauthlib.oauth2.rfc6749.errors.MissingCodeError: (missing_code) Missing code parameter in response.

It seems that for Google the parameter is named approvalCode.

bdesbiolles avatar Mar 06 '18 15:03 bdesbiolles

I had the same issue, just change

From

 # Fetch the access token
google.fetch_token(token_url, client_secret=client_secret,
                    authorization_response=redirect_response)

TO

 # Fetch the access token
google.fetch_token(token_url, client_secret=client_secret,
                   code=redirect_response)

although add this:

os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

and here just pass the code, like: 4/AgGw7I2EJZ43uGI7wvVY1Oc0Pv2s9DsD.......qdT0CY, not the url.

redirect_response = input('Paste the full redirect URL here:\n')

pd-Shah avatar Mar 03 '19 08:03 pd-Shah