Skip to content

Commit

Permalink
Merge d6112b2 into 900b109
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrdmn committed Jul 29, 2015
2 parents 900b109 + d6112b2 commit 3359a3d
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/edmodo/models.py
@@ -0,0 +1 @@
# Create your models here.
36 changes: 36 additions & 0 deletions allauth/socialaccount/providers/edmodo/provider.py
@@ -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)
38 changes: 38 additions & 0 deletions allauth/socialaccount/providers/edmodo/tests.py
@@ -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
}
""")
4 changes: 4 additions & 0 deletions allauth/socialaccount/providers/edmodo/urls.py
@@ -0,0 +1,4 @@
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
from .provider import EdmodoProvider

urlpatterns = default_urlpatterns(EdmodoProvider)
26 changes: 26 additions & 0 deletions allauth/socialaccount/providers/edmodo/views.py
@@ -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)
1 change: 1 addition & 0 deletions docs/installation.rst
Expand Up @@ -62,6 +62,7 @@ settings.py (Important - Please note 'django.contrib.sites' is required as INSTA
'allauth.socialaccount.providers.coinbase',
'allauth.socialaccount.providers.dropbox',
'allauth.socialaccount.providers.dropbox_oauth2',
'allauth.socialaccount.providers.edmodo',
'allauth.socialaccount.providers.evernote',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.flickr',
Expand Down
2 changes: 2 additions & 0 deletions docs/overview.rst
Expand Up @@ -43,6 +43,8 @@ Supported Providers

- Dropbox (OAuth, OAuth2)

- Edmodo (OAuth2)

- Evernote (OAuth)

- Facebook (both OAuth2 and JS SDK)
Expand Down
19 changes: 19 additions & 0 deletions docs/providers.rst
Expand Up @@ -56,6 +56,25 @@ The Baidu OAuth2 authentication documentation:
http://developer.baidu.com/wiki/index.php?title=docs/oauth/rest/file_data_apis_lista


Edmodo
------

The Edmodo OAuth2 documentation:

https://developers.edmodo.com/edmodo-connect/edmodo-connect-overview-getting-started/

You can optionally specify additional permissions to use. If no `SCOPE` value
is set, the Edmodo provider will use `basic` by default.::

SOCIALACCOUNT_PROVIDERS = {
'edmodo': {
'SCOPE': ['basic', 'read_groups', 'read_connections',
'read_user_email', 'create_messages',
'write_library_items']
}
}


Evernote
----------

Expand Down
1 change: 1 addition & 0 deletions test_settings.py
Expand Up @@ -75,6 +75,7 @@
'allauth.socialaccount.providers.douban',
'allauth.socialaccount.providers.dropbox',
'allauth.socialaccount.providers.dropbox_oauth2',
'allauth.socialaccount.providers.edmodo',
'allauth.socialaccount.providers.evernote',
'allauth.socialaccount.providers.feedly',
'allauth.socialaccount.providers.facebook',
Expand Down

0 comments on commit 3359a3d

Please sign in to comment.