From cfe861bc37f48774dac7ecbbc7305a879c169a8b Mon Sep 17 00:00:00 2001 From: Akash Rathor Date: Sun, 8 Sep 2024 19:15:17 +0530 Subject: [PATCH] fix : linkedin OAuth2 new changes correction --- social_core/backends/linkedin.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/social_core/backends/linkedin.py b/social_core/backends/linkedin.py index f402a191..88cd96fe 100644 --- a/social_core/backends/linkedin.py +++ b/social_core/backends/linkedin.py @@ -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"), @@ -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 @@ -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)) @@ -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):