Skip to content

Commit

Permalink
fix : linkedin OAuth2 new changes correction
Browse files Browse the repository at this point in the history
  • Loading branch information
Akash-Rathor committed Sep 8, 2024
1 parent d9554fa commit cfe861b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions social_core/backends/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class LinkedinOAuth2(BaseOAuth2):
name = "linkedin-oauth2"
AUTHORIZATION_URL = "https://www.linkedin.com/oauth/v2/authorization"
ACCESS_TOKEN_URL = "https://www.linkedin.com/oauth/v2/accessToken"
USER_DETAILS_URL = "https://api.linkedin.com/v2/me?projection=({projection})"
USER_DETAILS_URL = "https://api.linkedin.com/v2/userinfo?projection=({projection})"
USER_EMAILS_URL = (
"https://api.linkedin.com/v2/emailAddress"
"?q=members&projection=(elements*(handle~))"
)
ACCESS_TOKEN_METHOD = "POST"
REDIRECT_STATE = False
DEFAULT_SCOPE = ["r_liteprofile"]
DEFAULT_SCOPE = ["openid", "profile", "email"]
EXTRA_DATA = [
("id", "id"),
("expires_in", "expires"),
Expand Down Expand Up @@ -83,10 +83,10 @@ def user_data(self, access_token, *args, **kwargs):
self.user_details_url(), headers=self.user_data_headers(access_token)
)

if "emailAddress" in set(self.setting("FIELD_SELECTORS", [])):
if "email" in set(self.setting("FIELD_SELECTORS", [])):
emails = self.email_data(access_token, *args, **kwargs)
if emails:
response["emailAddress"] = emails[0]
response["email"] = emails[0]

return response

Expand All @@ -96,7 +96,7 @@ def email_data(self, access_token, *args, **kwargs):
)
email_addresses = []
for element in response.get("elements", []):
email_address = element.get("handle~", {}).get("emailAddress")
email_address = element.get("handle~", {}).get("email")
email_addresses.append(email_address)
return list(filter(None, email_addresses))

Expand All @@ -122,17 +122,19 @@ def get_localized_name(name):
)
return name["localized"].get(locale, "")

fullname, first_name, last_name = self.get_user_names(
first_name=get_localized_name(response["firstName"]),
last_name=get_localized_name(response["lastName"]),
)
email = response.get("emailAddress", "")
response = self.user_data(access_token=response["access_token"])
first_name = (response.get("given_name", ""),)
last_name = (response.get("family_name", ""),)
email = response.get("email", "")
return {
"id": response.get("sub", ""),
"username": first_name + last_name,
"fullname": fullname,
"fullname": response.get("name", ""),
"first_name": first_name,
"last_name": last_name,
"email": email,
"is_email_verified": response.get("emai;_verified", False),
"picture": response.get("picture", ""),
}

def user_data_headers(self, access_token):
Expand Down

0 comments on commit cfe861b

Please sign in to comment.