Skip to content

Commit

Permalink
Added Daum OAuth2 (#1617)
Browse files Browse the repository at this point in the history
* Added Daum OAuth2

* refact code for peb8

* revert

* remove ascii

* break long string

* string serve to json

* add line
  • Loading branch information
xncbf authored and pennersr committed Feb 16, 2017
1 parent 9c2391a commit f1e3a41
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Jerome Leclanche
John Bazik
John Whitlock
Jonas Aule
JoonHwan Kim
Josh Owen
Josh Wright
Joshua Sorenson
Expand Down
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions allauth/socialaccount/providers/daum/provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from allauth.socialaccount import providers
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider


class DaumAccount(ProviderAccount):

def get_avatar_url(self):
return self.account.extra_data.get('bigImagePath')

def to_str(self):
return self.account.extra_data.get('nickname', self.account.uid)


class DaumProvider(OAuth2Provider):
id = 'Daum'
name = 'Daum'
account_class = DaumAccount

def extract_uid(self, data):
return str(data.get('id'))


providers.registry.register(DaumProvider)
22 changes: 22 additions & 0 deletions allauth/socialaccount/providers/daum/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase

from .provider import DaumProvider
import json


class DaumTests(OAuth2TestsMixin, TestCase):
provider_id = DaumProvider.id

def get_mocked_response(self):
result = dict()
result['userid'] = '38DTh'
result['id'] = 46287445
result['nickname'] = 'xncbf'
result['bigImagePath'] = 'https://img1.daumcdn.net/thumb/'
result['openProfile'] = 'https://img1.daumcdn.net/thumb/'
body = dict()
body['code'] = 200
body['message'] = 'OK'
body['result'] = result
return MockedResponse(200, json.dumps(body))
4 changes: 4 additions & 0 deletions allauth/socialaccount/providers/daum/urls.py
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 DaumProvider

urlpatterns = default_urlpatterns(DaumProvider)
27 changes: 27 additions & 0 deletions allauth/socialaccount/providers/daum/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
OAuth2LoginView,
OAuth2CallbackView)
from .provider import DaumProvider


class DaumOAuth2Adapter(OAuth2Adapter):
provider_id = DaumProvider.id
access_token_url = 'https://apis.daum.net/oauth2/token'
authorize_url = 'https://apis.daum.net/oauth2/authorize'
profile_url = 'https://apis.daum.net/user/v1/show.json'

def complete_login(self, request, app, token, **kwargs):
resp = requests.get(self.profile_url, params={
'access_token': token.token
})
extra_data = resp.json().get('result')
return self.get_provider().sociallogin_from_response(
request,
extra_data
)


oauth2_login = OAuth2LoginView.adapter_view(DaumOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DaumOAuth2Adapter)
1 change: 1 addition & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ settings.py (Important - Please note 'django.contrib.sites' is required as INSTA
'allauth.socialaccount.providers.bitbucket_oauth2',
'allauth.socialaccount.providers.bitly',
'allauth.socialaccount.providers.coinbase',
'allauth.socialaccount.providers.daum',
'allauth.socialaccount.providers.digitalocean',
'allauth.socialaccount.providers.discord',
'allauth.socialaccount.providers.douban',
Expand Down
2 changes: 2 additions & 0 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Supported Providers

- Bitly (OAuth2)

- Daum (OAuth2)

- Douban (OAuth2)

- Doximity (OAuth2)
Expand Down
10 changes: 10 additions & 0 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ Note that Bitbucket calls the ``client_id`` *Key* in their user interface.
Don't get confused by that; use the *Key* value for your ``client_id`` field.


daum
-----

App registration (get your key and secret here)
https://developers.daum.net/console

Development callback URL
http://127.0.0.1:8000/accounts/daum/login/callback/


Discord
-------

Expand Down
1 change: 1 addition & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'allauth.socialaccount.providers.bitbucket',
'allauth.socialaccount.providers.bitly',
'allauth.socialaccount.providers.coinbase',
'allauth.socialaccount.providers.daum',
'allauth.socialaccount.providers.douban',
'allauth.socialaccount.providers.doximity',
'allauth.socialaccount.providers.digitalocean',
Expand Down

0 comments on commit f1e3a41

Please sign in to comment.