Skip to content

Commit

Permalink
Fix internal server error when logging in with Facebook
Browse files Browse the repository at this point in the history
I'm not sure why I only just now ran into this problem.  It may be due to
a change on Facebook's end.  Anyway, now login should be working again.  :)

See litl/rauth#194

(cherry picked from commit 648b32d)
  • Loading branch information
Ann Yanich committed Apr 15, 2017
1 parent e993660 commit 61dbc78
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion flask_app/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,23 @@ def callback_rerequest_permissions(self):
def callback(self, callback_url):
if 'code' not in request.args:
return None, None, None, None

# 04.2017: Login with Facebook started throwing an internal server error
# when get_auth_session is called:
# "the JSON object must be str, not 'bytes'"
# "Decoder failed to handle access_token with data as returned by provider.
# A different decoder may be needed."
# It was the same one as on this Github issue: https://github.com/litl/rauth/issues/194
# The problem can be worked around by using this decoder function.
def oauth_decode(data):
new_data = data.decode("utf-8", "strict")
return json.loads(new_data)

oauth_session = self.service.get_auth_session(
data={'code': request.args['code'],
'grant_type': 'authorization_code',
'redirect_uri': callback_url}
'redirect_uri': callback_url},
decoder=oauth_decode
)

me = oauth_session.get('me', params={'fields': 'email,name,first_name'}).json()
Expand Down

0 comments on commit 61dbc78

Please sign in to comment.