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,31 @@
from allauth.account.models import EmailAddress
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class DripAccount(ProviderAccount):
pass
class DripProvider(OAuth2Provider):
id = "drip"
name = "Drip"
account_class = DripAccount
def extract_uid(self, data):
# no uid available, we generate one by hashing the email
uid = hash(data.get("email"))
return str(uid)
def extract_common_fields(self, data):
return dict(email=data.get("email"), name=data.get("name"))
def extract_email_addresses(self, data):
ret = []
email = data.get("email")
if email:
ret.append(EmailAddress(email=email, verified=True, primary=True))
return ret
provider_classes = [DripProvider]

View File

@@ -0,0 +1,20 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import DripProvider
class DripTests(OAuth2TestsMixin, TestCase):
provider_id = DripProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""{
"users":[{
"email": "john@acme.com",
"name": "John Doe",
"time_zone": "America/Los_Angeles"
}]
}""",
)

View File

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

View File

@@ -0,0 +1,33 @@
"""Views for Drip API."""
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import DripProvider
class DripOAuth2Adapter(OAuth2Adapter):
"""OAuth2Adapter for Drip API v3."""
provider_id = DripProvider.id
authorize_url = "https://www.getdrip.com/oauth/authorize"
access_token_url = "https://www.getdrip.com/oauth/token"
profile_url = "https://api.getdrip.com/v2/user"
def complete_login(self, request, app, token, **kwargs):
"""Complete login, ensuring correct OAuth header."""
headers = {"Authorization": "Bearer {0}".format(token.token)}
response = requests.get(self.profile_url, headers=headers)
response.raise_for_status()
extra_data = response.json()["users"][0]
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(DripOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DripOAuth2Adapter)