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,26 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class HubicAccount(ProviderAccount):
pass
class HubicProvider(OAuth2Provider):
id = "hubic"
name = "Hubic"
account_class = HubicAccount
def extract_uid(self, data):
return str(data["email"])
def extract_common_fields(self, data):
return dict(
email=data.get("email"),
username=data.get("firstname").lower() + data.get("lastname").lower(),
first_name=data.get("firstname"),
last_name=data.get("lastname"),
)
provider_classes = [HubicProvider]

View File

@@ -0,0 +1,33 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import HubicProvider
class HubicTests(OAuth2TestsMixin, TestCase):
provider_id = HubicProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{
"email": "user@example.com",
"firstname": "Test",
"activated": true,
"creationDate": "2014-04-17T17:04:01+02:00",
"language": "en",
"status": "ok",
"offer": "25g",
"lastname": "User"
}
""",
)
def get_login_response_json(self, with_refresh_token=True):
return '{\
"access_token": "testac",\
"expires_in": "3600",\
"refresh_token": "testrf",\
"token_type": "Bearer"\
}'

View File

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

View File

@@ -0,0 +1,30 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import HubicProvider
class HubicOAuth2Adapter(OAuth2Adapter):
provider_id = HubicProvider.id
access_token_url = "https://api.hubic.com/oauth/token"
authorize_url = "https://api.hubic.com/oauth/auth"
profile_url = "https://api.hubic.com/1.0/account"
redirect_uri_protocol = "https"
def complete_login(self, request, app, token, **kwargs):
token_type = kwargs["response"]["token_type"]
resp = requests.get(
self.profile_url,
headers={"Authorization": "%s %s" % (token_type, token.token)},
)
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(HubicOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(HubicOAuth2Adapter)