| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.account.models import EmailAddress |
| 4 |
from allauth.socialaccount import app_settings |
| 5 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 6 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 7 |
from allauth.socialaccount.providers.wahoo.views import WahooOAuth2Adapter |
| 8 |
|
| 9 |
|
| 10 |
class WahooAccount(ProviderAccount): |
| 11 |
def get_profile_url(self): |
| 12 |
return "https://api.wahooligan.com/v1/user" |
| 13 |
|
| 14 |
|
| 15 |
class WahooProvider(OAuth2Provider): |
| 16 |
id = "wahoo" |
| 17 |
name = "Wahoo" |
| 18 |
account_class = WahooAccount |
| 19 |
oauth2_adapter_class = WahooOAuth2Adapter |
| 20 |
|
| 21 |
def extract_uid(self, data): |
| 22 |
return str(data["id"]) |
| 23 |
|
| 24 |
def extract_common_fields(self, data): |
| 25 |
extra_common = super().extract_common_fields(data) |
| 26 |
extra_common.update( |
| 27 |
# Additional properties we ignore: gender, created_at, updated_at |
| 28 |
height=data.get("height"), |
| 29 |
weight=data.get("weight"), |
| 30 |
first=data.get("first"), |
| 31 |
last=data.get("last"), |
| 32 |
birth=data.get("birth"), |
| 33 |
) |
| 34 |
return extra_common |
| 35 |
|
| 36 |
def extract_email_addresses(self, data): |
| 37 |
email = EmailAddress( |
| 38 |
email=data.get("email"), |
| 39 |
primary=True, |
| 40 |
verified=False, |
| 41 |
) |
| 42 |
return [email] |
| 43 |
|
| 44 |
def get_default_scope(self): |
| 45 |
scope = ["user_read"] |
| 46 |
if app_settings.QUERY_EMAIL: |
| 47 |
scope.append("email") |
| 48 |
return scope |
| 49 |
|
| 50 |
|
| 51 |
provider_classes = [WahooProvider] |