| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.models import EmailAddress |
| 4 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
from allauth.socialaccount.providers.yahoo.views import YahooOAuth2Adapter |
| 7 |
|
| 8 |
|
| 9 |
class YahooAccount(ProviderAccount): |
| 10 |
pass |
| 11 |
|
| 12 |
|
| 13 |
class YahooProvider(OAuth2Provider): |
| 14 |
id = "yahoo" |
| 15 |
name = "Yahoo" |
| 16 |
account_class = YahooAccount |
| 17 |
oauth2_adapter_class = YahooOAuth2Adapter |
| 18 |
|
| 19 |
def get_default_scope(self): |
| 20 |
""" |
| 21 |
Doc on scopes available at |
| 22 |
https://developer.yahoo.com/oauth2/guide/yahoo_scopes/ |
| 23 |
""" |
| 24 |
return ["profile", "email"] |
| 25 |
|
| 26 |
def extract_uid(self, data): |
| 27 |
return data["sub"] |
| 28 |
|
| 29 |
def extract_common_fields(self, data): |
| 30 |
return dict( |
| 31 |
email=data["email"], |
| 32 |
last_name=data["family_name"], |
| 33 |
first_name=data["given_name"], |
| 34 |
) |
| 35 |
|
| 36 |
def extract_email_addresses(self, data): |
| 37 |
ret = [] |
| 38 |
email = data.get("email") |
| 39 |
if email and data.get("email_verified"): |
| 40 |
ret.append(EmailAddress(email=email, verified=True, primary=True)) |
| 41 |
return ret |
| 42 |
|
| 43 |
|
| 44 |
provider_classes = [YahooProvider] |