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,32 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class CoinbaseAccount(ProviderAccount):
def get_avatar_url(self):
return None
def to_str(self):
return self.account.extra_data.get(
"name", super(CoinbaseAccount, self).to_str()
)
class CoinbaseProvider(OAuth2Provider):
id = "coinbase"
name = "Coinbase"
account_class = CoinbaseAccount
def get_default_scope(self):
# See: https://coinbase.com/docs/api/permissions
return ["wallet:user:email"]
def extract_uid(self, data):
return str(data["id"])
def extract_common_fields(self, data):
# See: https://coinbase.com/api/doc/1.0/users/index.html
return dict(email=data["email"])
provider_classes = [CoinbaseProvider]

View File

@@ -0,0 +1,25 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import CoinbaseProvider
class CoinbaseTests(OAuth2TestsMixin, TestCase):
provider_id = CoinbaseProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""{
"id": "9da7a204-544e-5fd1-9a12-61176c5d4cd8",
"name": "User One",
"username": "user1",
"email": "user1@example.com",
"profile_location": null,
"profile_bio": null,
"profile_url": "https://coinbase.com/user1",
"avatar_url": "https://images.coinbase.com/avatar?h=vR%2FY8igBoPwuwGren5JMwvDNGpURAY%2F0nRIOgH%2FY2Qh%2BQ6nomR3qusA%2Bh6o2%0Af9rH&s=128",
"resource": "user",
"resource_path": "/v2/user"
}""",
)

View File

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

View File

@@ -0,0 +1,34 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import CoinbaseProvider
class CoinbaseOAuth2Adapter(OAuth2Adapter):
provider_id = CoinbaseProvider.id
@property
def authorize_url(self):
return "https://www.coinbase.com/oauth/authorize"
@property
def access_token_url(self):
return "https://www.coinbase.com/oauth/token"
@property
def profile_url(self):
return "https://api.coinbase.com/v2/user"
def complete_login(self, request, app, token, **kwargs):
response = requests.get(self.profile_url, params={"access_token": token})
extra_data = response.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(CoinbaseOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(CoinbaseOAuth2Adapter)