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,29 @@
"""Provider for Dwolla"""
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class DwollaAccount(ProviderAccount):
"""Dwolla Account"""
pass
class DwollaProvider(OAuth2Provider):
"""Provider for Dwolla"""
id = "dwolla"
name = "Dwolla"
account_class = DwollaAccount
def extract_uid(self, data):
return str(data.get("id", None))
def extract_common_fields(self, data):
return dict(
name=data.get("name"),
)
provider_classes = [DwollaProvider]

View File

@@ -0,0 +1,31 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import DwollaProvider
class DwollaTests(OAuth2TestsMixin, TestCase):
provider_id = DwollaProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""{
"id": "123",
"_links":{"account":{"href":"http://localhost"}},
"name":"John Doe"
}""",
)
def get_login_response_json(self, with_refresh_token=True):
rt = ""
if with_refresh_token:
rt = ',"refresh_token": "testrf"'
return (
"""{
"uid":"weibo",
"access_token":"testac",
"_links":{"account":{"href":"http://localhost"}}
%s }"""
% rt
)

View File

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

View File

@@ -0,0 +1,59 @@
import requests
from django.conf import settings
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import DwollaProvider
ENVIRONMENTS = {
"production": {
"auth_url": "https://www.dwolla.com/oauth/v2/authenticate",
"token_url": "https://www.dwolla.com/oauth/v2/token",
},
"sandbox": {
"auth_url": "https://uat.dwolla.com/oauth/v2/authenticate",
"token_url": "https://uat.dwolla.com/oauth/v2/token",
},
}
ENV = (
getattr(settings, "SOCIALACCOUNT_PROVIDERS", {})
.get("dwolla", {})
.get("ENVIRONMENT", "production")
)
AUTH_URL = ENVIRONMENTS[ENV]["auth_url"]
TOKEN_URL = ENVIRONMENTS[ENV]["token_url"]
class DwollaOAuth2Adapter(OAuth2Adapter):
"""Dwolla Views Adapter"""
scope_delimiter = "|"
provider_id = DwollaProvider.id
access_token_url = TOKEN_URL
authorize_url = AUTH_URL
def complete_login(self, request, app, token, response, **kwargs):
resp = requests.get(
response["_links"]["account"]["href"],
headers={
"authorization": "Bearer %s" % token.token,
"accept": "application/vnd.dwolla.v1.hal+json",
},
)
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(DwollaOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DwollaOAuth2Adapter)