From 61dbc78d77323cfdb0ec67874a12b21bc8ce90e5 Mon Sep 17 00:00:00 2001 From: Ann Yanich Date: Sat, 15 Apr 2017 16:43:38 +0200 Subject: [PATCH] Fix internal server error when logging in with Facebook 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 https://github.com/litl/rauth/issues/194 (cherry picked from commit 648b32d) --- flask_app/oauth.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/flask_app/oauth.py b/flask_app/oauth.py index d85f245..69f21b9 100644 --- a/flask_app/oauth.py +++ b/flask_app/oauth.py @@ -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()