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,39 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class EdmodoAccount(ProviderAccount):
def get_profile_url(self):
return self.account.extra_data.get("profile_url")
def get_avatar_url(self):
return self.account.extra_data.get("avatar_url")
class EdmodoProvider(OAuth2Provider):
id = "edmodo"
name = "Edmodo"
account_class = EdmodoAccount
def get_default_scope(self):
return ["basic"]
def extract_uid(self, data):
return str(data["id"])
def extract_common_fields(self, data):
return dict(
first_name=data.get("first_name"),
last_name=data.get("last_name"),
email=data.get("email", ""),
)
def extract_extra_data(self, data):
return dict(
user_type=data.get("type"),
profile_url=data.get("url"),
avatar_url=data.get("avatars").get("large"),
)
provider_classes = [EdmodoProvider]

View File

@@ -0,0 +1,44 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import EdmodoProvider
class EdmodoTests(OAuth2TestsMixin, TestCase):
provider_id = EdmodoProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{
"url": "https://api.edmodo.com/users/74721257",
"id": 74721257,
"type": "teacher",
"username": "getacclaim-teacher1",
"user_title": null,
"first_name": "Edmodo Test",
"last_name": "Teacher",
"time_zone": "America/New_York",
"utc_offset": -18000,
"locale": "en",
"gender": null,
"start_level": null,
"end_level": null,
"about": null,
"premium": false,
"school": {"url": "https://api.edmodo.com/schools/559253", "id": 559253},
"verified_institution_member": true,
"coppa_verified": false,
"subjects": null,
"avatars": {
"small":
"https://api.edmodo.com/users/74721257/avatar?type=small&u=670329ncqnf8fxv7tya24byn5",
"large":
"https://api.edmodo.com/users/74721257/avatar?type=large&u=670329ncqnf8fxv7tya24byn5"
},
"email":"test@example.com",
"sync_enabled": false
}
""",
) # noqa

View File

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

View File

@@ -0,0 +1,25 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import EdmodoProvider
class EdmodoOAuth2Adapter(OAuth2Adapter):
provider_id = EdmodoProvider.id
access_token_url = "https://api.edmodo.com/oauth/token"
authorize_url = "https://api.edmodo.com/oauth/authorize"
profile_url = "https://api.edmodo.com/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()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(EdmodoOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(EdmodoOAuth2Adapter)