From 75ca888e5e6c52bf8a018a14d468eadeb8c07d4e Mon Sep 17 00:00:00 2001 From: Bibhas Date: Wed, 27 Jan 2021 19:19:17 +0530 Subject: [PATCH] Handler for invalid JSON response from Linkedin (#1011) --- funnel/loginproviders/linkedin.py | 12 +++++++++-- .../static/translations/hi_IN/messages.json | 1 + .../hi_IN/LC_MESSAGES/messages.mo | Bin 172623 -> 172623 bytes .../hi_IN/LC_MESSAGES/messages.po | 20 +++++++++++------- funnel/translations/messages.pot | 20 +++++++++++------- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/funnel/loginproviders/linkedin.py b/funnel/loginproviders/linkedin.py index 0775b046a..d4d6273b0 100644 --- a/funnel/loginproviders/linkedin.py +++ b/funnel/loginproviders/linkedin.py @@ -1,8 +1,10 @@ from urllib.parse import quote from uuid import uuid4 -from flask import redirect, request, session +from flask import current_app, redirect, request, session +from sentry_sdk import capture_exception +from simplejson.errors import JSONDecodeError import requests from baseframe import _ @@ -14,7 +16,7 @@ class LinkedInProvider(LoginProvider): auth_url = 'https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id={client_id}&scope={scope}&redirect_uri={redirect_uri}&state={state}' - token_url = 'https://www.linkedin.com/uas/oauth2/accessToken' + token_url = 'https://www.linkedin.com/uas/oauth2/accessToken' # nosec user_info = 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName)' user_email = 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))' @@ -78,6 +80,12 @@ def callback(self): "Unable to authenticate via LinkedIn. Internal details: {error}" ).format(error=e) ) + except JSONDecodeError as e: + current_app.logger.error(e.msg) + capture_exception(e) + raise LoginCallbackError( + _("LinkedIn is having intermittent issues. Try again?") + ) if 'error' in response: raise LoginCallbackError(response['error']) try: diff --git a/funnel/static/translations/hi_IN/messages.json b/funnel/static/translations/hi_IN/messages.json index 9c34754af..cbcb2fd7b 100644 --- a/funnel/static/translations/hi_IN/messages.json +++ b/funnel/static/translations/hi_IN/messages.json @@ -737,6 +737,7 @@ null, "LinkedIn के ज़रिए प्रमाणित करने में असमर्थ रहा. आंतरिक विवरण: {error}" ], + "LinkedIn is having intermittent issues. Try again?": [null, ""], "Unable to retrieve user details from LinkedIn. Please try again": [ null, "LinkedIn से यूजर की जानकारी प्राप्त करने में असमर्थ रहा. आंतरिक विवरण: {error}" diff --git a/funnel/translations/hi_IN/LC_MESSAGES/messages.mo b/funnel/translations/hi_IN/LC_MESSAGES/messages.mo index 3d8e32cae493a51ff3ae04c5f6f2910b06ed9385..f159bb5cd8144095fe70a1722f1307778fb3492a 100644 GIT binary patch delta 26 icmX?qgzNkft_@2+vYRUy8d@0|H?R4)ea%P4#Tx*qAPlDf delta 26 icmX?qgzNkft_@2+vYRRx8dw>aHm~`(ea%P4#Tx*p{0yZ4 diff --git a/funnel/translations/hi_IN/LC_MESSAGES/messages.po b/funnel/translations/hi_IN/LC_MESSAGES/messages.po index c8843b50a..f8621907f 100644 --- a/funnel/translations/hi_IN/LC_MESSAGES/messages.po +++ b/funnel/translations/hi_IN/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: webmaster@hasgeek.com\n" -"POT-Creation-Date: 2021-01-25 10:05+0530\n" +"POT-Creation-Date: 2021-01-27 11:13+0530\n" "PO-Revision-Date: 2020-12-17 13:47+0530\n" "Last-Translator: Ritesh Raj\n" "Language: hi\n" @@ -1340,12 +1340,12 @@ msgstr "ईवेंट का स्थान" msgid "You denied the GitHub login request" msgstr "आपने GitHub लॉग इन अनुरोध को ख़ारिज कर दिया है" -#: funnel/loginproviders/github.py:47 funnel/loginproviders/linkedin.py:58 +#: funnel/loginproviders/github.py:47 funnel/loginproviders/linkedin.py:60 msgid "This server's callback URL is misconfigured" msgstr "सर्वर की कॉलबैक URL की विन्यास गलत है" #: funnel/loginproviders/github.py:50 funnel/loginproviders/google.py:45 -#: funnel/loginproviders/linkedin.py:61 +#: funnel/loginproviders/linkedin.py:63 msgid "Unknown failure" msgstr "अज्ञात समस्या" @@ -1385,25 +1385,29 @@ msgstr "LinkedIn" msgid "GitHub" msgstr "GitHub" -#: funnel/loginproviders/linkedin.py:50 +#: funnel/loginproviders/linkedin.py:52 msgid "We detected a possible attempt at cross-site request forgery" msgstr "हमें क्रॉस-साइट अनुरोध के भीतर संभावित धोखाधड़ी का पता चला है" -#: funnel/loginproviders/linkedin.py:54 +#: funnel/loginproviders/linkedin.py:56 msgid "You denied the LinkedIn login request" msgstr "आपने LinkedIn लॉग इन अनुरोध को ख़ारिज कर दिया" -#: funnel/loginproviders/linkedin.py:77 funnel/loginproviders/linkedin.py:91 +#: funnel/loginproviders/linkedin.py:79 funnel/loginproviders/linkedin.py:99 msgid "Unable to authenticate via LinkedIn. Internal details: {error}" msgstr "LinkedIn के ज़रिए प्रमाणित करने में असमर्थ रहा. आंतरिक विवरण: {error}" -#: funnel/loginproviders/linkedin.py:98 +#: funnel/loginproviders/linkedin.py:87 +msgid "LinkedIn is having intermittent issues. Try again?" +msgstr "" + +#: funnel/loginproviders/linkedin.py:106 msgid "Unable to retrieve user details from LinkedIn. Please try again" msgstr "" "LinkedIn से यूजर की जानकारी प्राप्त करने में असमर्थ रहा. आंतरिक विवरण: " "{error}" -#: funnel/loginproviders/linkedin.py:109 +#: funnel/loginproviders/linkedin.py:117 msgid "Unable to fetch email from LinkedIn. Internal details: {error}" msgstr "LinkedIn से ईमेल प्राप्त करने में असमर्थ रहा. आंतरिक विवरण: {error}" diff --git a/funnel/translations/messages.pot b/funnel/translations/messages.pot index 43e1cee51..bb2c043b7 100644 --- a/funnel/translations/messages.pot +++ b/funnel/translations/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-01-25 10:05+0530\n" +"POT-Creation-Date: 2021-01-27 11:13+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1277,12 +1277,12 @@ msgstr "" msgid "You denied the GitHub login request" msgstr "" -#: funnel/loginproviders/github.py:47 funnel/loginproviders/linkedin.py:58 +#: funnel/loginproviders/github.py:47 funnel/loginproviders/linkedin.py:60 msgid "This server's callback URL is misconfigured" msgstr "" #: funnel/loginproviders/github.py:50 funnel/loginproviders/google.py:45 -#: funnel/loginproviders/linkedin.py:61 +#: funnel/loginproviders/linkedin.py:63 msgid "Unknown failure" msgstr "" @@ -1320,23 +1320,27 @@ msgstr "" msgid "GitHub" msgstr "" -#: funnel/loginproviders/linkedin.py:50 +#: funnel/loginproviders/linkedin.py:52 msgid "We detected a possible attempt at cross-site request forgery" msgstr "" -#: funnel/loginproviders/linkedin.py:54 +#: funnel/loginproviders/linkedin.py:56 msgid "You denied the LinkedIn login request" msgstr "" -#: funnel/loginproviders/linkedin.py:77 funnel/loginproviders/linkedin.py:91 +#: funnel/loginproviders/linkedin.py:79 funnel/loginproviders/linkedin.py:99 msgid "Unable to authenticate via LinkedIn. Internal details: {error}" msgstr "" -#: funnel/loginproviders/linkedin.py:98 +#: funnel/loginproviders/linkedin.py:87 +msgid "LinkedIn is having intermittent issues. Try again?" +msgstr "" + +#: funnel/loginproviders/linkedin.py:106 msgid "Unable to retrieve user details from LinkedIn. Please try again" msgstr "" -#: funnel/loginproviders/linkedin.py:109 +#: funnel/loginproviders/linkedin.py:117 msgid "Unable to fetch email from LinkedIn. Internal details: {error}" msgstr ""