This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
from allauth.account.models import EmailAddress
from allauth.socialaccount import app_settings
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class WahooAccount(ProviderAccount):
def get_profile_url(self):
return "https://api.wahooligan.com/v1/user"
class WahooProvider(OAuth2Provider):
id = "wahoo"
name = "Wahoo"
account_class = WahooAccount
def extract_uid(self, data):
return str(data["id"])
def extract_common_fields(self, data):
extra_common = super(WahooProvider, self).extract_common_fields(data)
extra_common.update(
# Additional properties we ignore: gender, created_at, updated_at
height=data.get("height"),
weight=data.get("weight"),
first=data.get("first"),
last=data.get("last"),
birth=data.get("birth"),
)
return extra_common
def extract_email_addresses(self, data):
email = EmailAddress(
email=data.get("email"),
primary=True,
verified=False,
)
return [email]
def get_default_scope(self):
scope = ["user_read"]
if app_settings.QUERY_EMAIL:
scope.append("email")
return scope
provider_classes = [WahooProvider]

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from allauth.socialaccount.providers.wahoo.provider import WahooProvider
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
class WahooTests(OAuth2TestsMixin, TestCase):
provider_id = WahooProvider.id
def get_mocked_response(self):
# https://cloud-api.wahooligan.com/#users
return MockedResponse(
200,
"""
{
"id": 60462,
"height": "2.0",
"weight": "80.0",
"first": "Bob",
"last": "Smith",
"email": "sample@test-domain.com",
"birth": "1980-10-02",
"gender": 1,
"created_at": "2018-10-23T15:38:23.000Z",
"updated_at": "2018-10-24T20:46:40.000Z"
}
""",
)

View File

@@ -0,0 +1,6 @@
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
from .provider import WahooProvider
urlpatterns = default_urlpatterns(WahooProvider)

View File

@@ -0,0 +1,27 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import WahooProvider
class WahooOauth2Adapter(OAuth2Adapter):
provider_id = WahooProvider.id
access_token_url = "https://api.wahooligan.com/oauth/token"
authorize_url = "https://api.wahooligan.com/oauth/authorize"
profile_url = "https://api.wahooligan.com/v1/user"
def complete_login(self, request, app, token, **kwargs):
headers = {"Authorization": "Bearer {0}".format(token.token)}
resp = requests.get(self.profile_url, headers=headers)
resp.raise_for_status()
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(WahooOauth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WahooOauth2Adapter)