-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Daum OAuth2 * refact code for peb8 * revert * remove ascii * break long string * string serve to json * add line
- Loading branch information
Showing
11 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
Empty file.
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,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) |
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,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)) |
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 DaumProvider | ||
|
||
urlpatterns = default_urlpatterns(DaumProvider) |
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,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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ Supported Providers | |
|
||
- Bitly (OAuth2) | ||
|
||
- Daum (OAuth2) | ||
|
||
- Douban (OAuth2) | ||
|
||
- Doximity (OAuth2) | ||
|
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