Skip to content

Commit 5988ff5

Browse files
committed
chore(backend): drop no longer supported OAuth1 backend for Yahoo
- Drop OAuth1 backend and tests - Add OAuth2 tests - Fixed OAuth2 username mapping to match documentation Issue #1176
1 parent 97326f6 commit 5988ff5

File tree

2 files changed

+21
-117
lines changed

2 files changed

+21
-117
lines changed

social_core/backends/yahoo.py

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,7 @@
77

88
from social_core.utils import handle_http_errors
99

10-
from .oauth import BaseOAuth1, BaseOAuth2
11-
12-
13-
class YahooOAuth(BaseOAuth1):
14-
"""Yahoo OAuth authentication backend. DEPRECATED"""
15-
16-
name = "yahoo-oauth"
17-
ID_KEY = "guid"
18-
AUTHORIZATION_URL = "https://api.login.yahoo.com/oauth/v2/request_auth"
19-
REQUEST_TOKEN_URL = "https://api.login.yahoo.com/oauth/v2/get_request_token"
20-
ACCESS_TOKEN_URL = "https://api.login.yahoo.com/oauth/v2/get_token"
21-
EXTRA_DATA = [
22-
("guid", "id"),
23-
("access_token", "access_token"),
24-
("expires", "expires"),
25-
]
26-
27-
def get_user_details(self, response):
28-
"""Return user details from Yahoo Profile"""
29-
fullname, first_name, last_name = self.get_user_names(
30-
first_name=response.get("givenName"), last_name=response.get("familyName")
31-
)
32-
emails = [email for email in response.get("emails", []) if email.get("handle")]
33-
emails.sort(key=lambda e: e.get("primary", False), reverse=True)
34-
return {
35-
"username": response.get("nickname"),
36-
"email": emails[0]["handle"] if emails else "",
37-
"fullname": fullname,
38-
"first_name": first_name,
39-
"last_name": last_name,
40-
}
41-
42-
def user_data(self, access_token, *args, **kwargs):
43-
"""Loads user data from service"""
44-
url = "https://social.yahooapis.com/v1/user/{0}/profile?format=json"
45-
return self.get_json(
46-
url.format(self._get_guid(access_token)), auth=self.oauth_auth(access_token)
47-
)["profile"]
48-
49-
def _get_guid(self, access_token):
50-
"""
51-
Because you have to provide GUID for every API request it's also
52-
returned during one of OAuth calls
53-
"""
54-
return self.get_json(
55-
"https://social.yahooapis.com/v1/me/guid?format=json",
56-
auth=self.oauth_auth(access_token),
57-
)["guid"]["value"]
10+
from .oauth import BaseOAuth2
5811

5912

6013
class YahooOAuth2(BaseOAuth2):
@@ -89,7 +42,7 @@ def get_user_details(self, response):
8942

9043
email = response.get("email")
9144
return {
92-
"username": response.get("nickname"),
45+
"username": response.get("preferred_username", response.get("nickname")),
9346
"email": email,
9447
"fullname": fullname,
9548
"first_name": first_name,
Lines changed: 19 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,36 @@
1-
# pyright: reportAttributeAccessIssue=false
21
import json
3-
from urllib.parse import urlencode
42

5-
import requests
6-
import responses
3+
from .oauth import BaseAuthUrlTestMixin, OAuth2Test
74

8-
from .oauth import OAuth1AuthUrlTestMixin, OAuth1Test
95

10-
11-
class YahooOAuth1Test(OAuth1Test, OAuth1AuthUrlTestMixin):
12-
backend_path = "social_core.backends.yahoo.YahooOAuth"
13-
user_data_url = "https://social.yahooapis.com/v1/user/a-guid/profile?format=json"
14-
expected_username = "foobar"
15-
access_token_body = json.dumps({"access_token": "foobar", "token_type": "bearer"})
16-
request_token_body = urlencode(
6+
class YahooOAuth2Test(OAuth2Test, BaseAuthUrlTestMixin):
7+
backend_path = "social_core.backends.yahoo.YahooOAuth2"
8+
user_data_url = "https://api.login.yahoo.com/openid/v1/userinfo"
9+
expected_username = "j.doe"
10+
access_token_body = json.dumps(
1711
{
18-
"oauth_token_secret": "foobar-secret",
19-
"oauth_token": "foobar",
20-
"oauth_callback_confirmed": "true",
12+
"access_token": "UNQO1djO5xpaKm3_KbECBKB5mlFr6tSZTOLrrJCprtT1X1UFljpxiS5iSue8u_n8ah1WbL6sTNw3HPFHicyXDbTs7aSrbIe.rx9n9dzX7xZjx8dyF2Ap1a6J_nw4k56a5mCOuTd.ZFQENgGtHwM0DRFVeDNTAx_WzhqDGPCqhtsNICuuY30soFZGS11FTlUk7Gy0ISjxLRAjIZVtpojnY5p8XuT1qUtAheWq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IYnpsTlFTMHRKbk05WTI5dWMzVnRaWEp6WldOeVpYUW1lRDAxT0EtLSIsImlzcyI6Imh0dHBzOi8vbG9naW4ueWFob28uY29tIiwiZXhwIjoxNDQzODI3MTMwLCJub25jZSI6IjEyMzQ1IiwiaWF0IjoxNDQzODIzNTMwfQ.n7oEFi5028StcI41Hkh6lLYK4PmF7pT4AIXrQ_62nfDEZj2g0oYjSLFPJp4IqF6LefwcCQ9FHT5X9eC8A7peqw",
2118
}
2219
)
23-
guid_body = json.dumps(
24-
{"guid": {"uri": "https://social.yahooapis.com/v1/me/guid", "value": "a-guid"}}
25-
)
2620
user_data_body = json.dumps(
2721
{
28-
"profile": {
29-
"bdRestricted": True,
30-
"memberSince": "2007-12-11T14:40:30Z",
31-
"image": {
32-
"width": 192,
33-
"imageUrl": "http://l.yimg.com/dh/ap/social/profile/"
34-
"profile_b192.png",
35-
"size": "192x192",
36-
"height": 192,
37-
},
38-
"created": "2013-03-18T04:15:08Z",
39-
"uri": "https://social.yahooapis.com/v1/user/a-guid/profile",
40-
"isConnected": False,
41-
"profileUrl": "http://profile.yahoo.com/a-guid",
42-
"guid": "a-guid",
43-
"nickname": "foobar",
44-
"emails": [
45-
{
46-
"handle": "[email protected]",
47-
"id": 1,
48-
"primary": True,
49-
"type": "HOME",
50-
},
51-
{
52-
"handle": "[email protected]",
53-
"id": 2,
54-
"type": "HOME",
55-
},
56-
],
57-
}
22+
"sub": "FSVIDUW3D7FSVIDUW3D72F2F", # user identifier
23+
"name": "Jane Doe",
24+
"given_name": "Jane",
25+
"family_name": "Doe",
26+
"preferred_username": "j.doe",
27+
"email": "[email protected]",
28+
"picture": "http://example.com/janedoe/me.jpg",
5829
}
5930
)
6031

6132
def test_login(self) -> None:
62-
responses.add(
63-
responses.GET,
64-
"https://social.yahooapis.com/v1/me/guid?format=json",
65-
status=200,
66-
body=self.guid_body,
67-
)
6833
self.do_login()
6934

7035
def test_partial_pipeline(self) -> None:
71-
responses.add(
72-
responses.GET,
73-
"https://social.yahooapis.com/v1/me/guid?format=json",
74-
status=200,
75-
body=self.guid_body,
76-
)
7736
self.do_partial_pipeline()
78-
79-
def test_get_user_details(self) -> None:
80-
responses.add(
81-
responses.GET, self.user_data_url, status=200, body=self.user_data_body
82-
)
83-
response = requests.get(self.user_data_url, timeout=1)
84-
user_details = self.backend.get_user_details(response.json()["profile"])
85-
self.assertEqual(user_details["email"], "[email protected]")

0 commit comments

Comments
 (0)