Skip to content

Commit

Permalink
Handler for invalid JSON response from Linkedin (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibhas authored Jan 27, 2021
1 parent a0977c3 commit 75ca888
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
12 changes: 10 additions & 2 deletions funnel/loginproviders/linkedin.py
Original file line number Diff line number Diff line change
@@ -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 _
Expand All @@ -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~))'

Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions funnel/static/translations/hi_IN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Binary file modified funnel/translations/hi_IN/LC_MESSAGES/messages.mo
Binary file not shown.
20 changes: 12 additions & 8 deletions funnel/translations/hi_IN/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\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"
Expand Down Expand Up @@ -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 "अज्ञात समस्या"

Expand Down Expand Up @@ -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}"

Expand Down
20 changes: 12 additions & 8 deletions funnel/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down

0 comments on commit 75ca888

Please sign in to comment.