Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from allauth.socialaccount import providers | ||
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' | ||
package = 'allauth.socialaccount.providers.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')) | ||
|
||
providers.registry.register(EdmodoProvider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from allauth.socialaccount.tests import create_oauth2_tests | ||
from allauth.tests import MockedResponse | ||
from allauth.socialaccount.providers import registry | ||
|
||
from .provider import EdmodoProvider | ||
|
||
|
||
class EdmodoTests(create_oauth2_tests(registry.by_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 | ||
} | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns | ||
from .provider import EdmodoProvider | ||
|
||
urlpatterns = default_urlpatterns(EdmodoProvider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import requests | ||
|
||
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter, | ||
OAuth2LoginView, | ||
OAuth2CallbackView) | ||
from allauth.socialaccount.providers import registry | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters