Google oauth2 authentication throws an exception in rauth
See original GitHub issueHi,
I have implemented google oauth2 today. I was expecting it to work as simple as facebook, but I get an exception in rauth when I try to get the session.
def google_login():
redirect_uri = url_for('google_authorized', _external=True)
params = {'redirect_uri': redirect_uri, 'response_type': 'code', 'scope': 'email'}
return redirect(google_oauth2.get_authorize_url(**params))
def google_authorized():
if not 'code' in request.args:
flash('Whoops. You did not authorize the request. Try again.', 'warning')
return redirect(url_for('index'))
redirect_uri = url_for('google_authorized', _external=True)
data = dict(code=request.args['code'], redirect_uri=redirect_uri)
gg_session = google_oauth2.get_auth_session(data=data)
I can see the code with a long value in request.args
. I wonder what else is missing, to get this exception and error:
KeyError: 'Decoder failed to handle access_token with data as returned by provider. A different decoder may be needed. Provider returned: {\n "error" : "invalid_request"\n}'
Trace:
File "/home/hooman/workspace/F11A/src/lib/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/home/hooman/workspace/F11A/src/lib/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/hooman/workspace/F11A/src/lib/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/home/hooman/workspace/F11A/src/lib/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/hooman/workspace/F11A/src/lib/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/home/hooman/workspace/F11A/src/lib/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/hooman/workspace/F11A/src/application/views.py", line 433, in google_authorized
gg_session = google_oauth2.get_auth_session(data=data)
File "/home/hooman/workspace/F11A/src/lib/rauth/service.py", line 505, in get_auth_session
return self.get_session(self.get_access_token(method, **kwargs))
File "/home/hooman/workspace/F11A/src/lib/rauth/service.py", line 491, in get_access_token
access_token, = process_token_request(r, decoder, key)
File "/home/hooman/workspace/F11A/src/lib/rauth/service.py", line 25, in process_token_request
raise KeyError(PROCESS_TOKEN_ERROR.format(key=bad_key, raw=r.content))
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Authorization Errors | Device Access - Google Developers
When attempting to get an access or refresh token, you will get an "Invalid client" error if you provide an incorrect OAuth 2.0...
Read more >Google OAuth 2 authorization - Error: redirect_uri_mismatch
I was struggling to solve this issue with django-rest-social-auth and angular frontend. Its working when I passed 'postmessage' as redirect_uri. Thanks a lot ......
Read more >How to Store Authentication Data in a Database. Part 4
To inspect this process, let's take a look at the OAuth 2.0 protocol. We will use Flask framework and the Rauth OAuth 2.0...
Read more >Programmatic authentication | Identity-Aware Proxy
Authenticating from a mobile app · Create an OAuth 2.0 client ID for your mobile app in the same project as the IAP-secured...
Read more >An Introduction to OAuth2 Authentication - Linode
OAuth vs OAuth2. OAuth1 was originally based on Flickr's authorization protocol and Google's AuthSub utility. OAuth2 completely overhauled the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The method is fine, but you need to pass in a JSON decoder because the endpoint is returning a JSON blob. This is covered in the rauth API documentation and the error message also indicates that a different decoder is likely needed; the default is indicated by the spec.
Alternatively you can use the raw request object, like you did.
I would like to see the exact code that’s failing: if you examine the actual codepath, there is no difference between calling
get_auth_session(data=data, decoder=json.loads)
andget_raw_access_token(data=data, decoder=json.loads)
(in fact,get_auth_session
callsget_raw_access_token
) apart from the fact that the return values are different, of course. In other words, I shouldn’t be possible for one to work and the other to not.In order to see what is going on, please isolate the problem into a reproducible case so we can take a look at it.