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,21 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class AsanaAccount(ProviderAccount):
pass
class AsanaProvider(OAuth2Provider):
id = "asana"
name = "Asana"
account_class = AsanaAccount
def extract_uid(self, data):
return str(data["id"])
def extract_common_fields(self, data):
return dict(email=data.get("email"), name=data.get("name"))
provider_classes = [AsanaProvider]

View File

@@ -0,0 +1,17 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import AsanaProvider
class AsanaTests(OAuth2TestsMixin, TestCase):
provider_id = AsanaProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{"data": {"photo": null, "workspaces": [{"id": 31337, "name": "example.com"},
{"id": 3133777, "name": "Personal Projects"}], "email": "test@example.com",
"name": "Test Name", "id": 43748387}}""",
)

View File

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

View File

@@ -0,0 +1,25 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import AsanaProvider
class AsanaOAuth2Adapter(OAuth2Adapter):
provider_id = AsanaProvider.id
access_token_url = "https://app.asana.com/-/oauth_token"
authorize_url = "https://app.asana.com/-/oauth_authorize"
profile_url = "https://app.asana.com/api/1.0/users/me"
def complete_login(self, request, app, token, **kwargs):
resp = requests.get(self.profile_url, params={"access_token": token.token})
extra_data = resp.json()["data"]
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(AsanaOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(AsanaOAuth2Adapter)