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,41 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class ExistAccount(ProviderAccount):
def get_profile_url(self):
return "https://exist.io/api/2/accounts/profile/"
def get_avatar_url(self):
return self.account.extra_data.get("avatar")
def to_str(self):
name = super().to_str()
return self.account.extra_data.get("name", name)
class ExistProvider(OAuth2Provider):
id = "exist"
name = "Exist.io"
account_class = ExistAccount
def extract_uid(self, data):
return data.get("username")
def extract_common_fields(self, data):
extra_common = super().extract_common_fields(data)
extra_common.update(
username=data.get("username"),
first_name=data.get("first_name"),
last_name=data.get("last_name"),
avatar=data.get("avatar"),
timezone=data.get("timezone"),
local_time=data.get("local_time"),
)
return extra_common
def get_default_scope(self):
return ["mood_read", "health_read", "productivity_read"]
provider_classes = [ExistProvider]

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from allauth.socialaccount.providers.exist.provider import ExistProvider
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
class ExistTests(OAuth2TestsMixin, TestCase):
provider_id = ExistProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{
"id": 1,
"username": "josh",
"first_name": "Josh",
"last_name": "Sharp",
"bio": "I made this thing you're using.",
"url": "http://hellocode.co/",
"avatar": "https://exist.io/static/media/avatars/josh_2.png",
"timezone": "Australia/Melbourne",
"local_time": "2020-07-31T22:33:49.359+10:00",
"private": false,
"imperial_units": false,
"imperial_distance": false,
"imperial_weight": false,
"imperial_energy": false,
"imperial_liquid": false,
"imperial_temperature": false,
"attributes": []
}
""",
)

View File

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

View File

@@ -0,0 +1,26 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import ExistProvider
class ExistOAuth2Adapter(OAuth2Adapter):
provider_id = ExistProvider.id
access_token_url = "https://exist.io/oauth2/access_token"
authorize_url = "https://exist.io/oauth2/authorize"
profile_url = "https://exist.io/api/2/accounts/profile/"
def complete_login(self, request, app, token, **kwargs):
headers = {"Authorization": "Bearer {0}".format(token.token)}
resp = requests.get(self.profile_url, headers=headers)
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(ExistOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(ExistOAuth2Adapter)