requests / requests-oauthlib

OAuthlib support for Python-Requests!
https://requests-oauthlib.readthedocs.org/
ISC License
1.73k stars 423 forks source link

Missing code parameter while fetching token for Google #308

Open bdesbiolles opened 6 years ago

bdesbiolles commented 6 years ago

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.

pd-Shah commented 5 years ago

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')