Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Line Provider * Modify Line Provider Test Code (MockedResponse) * Fix line provider flake8 error * modify test_settings.py, installation.rst
- Loading branch information
Showing
11 changed files
with
87 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,27 @@ | ||
from allauth.socialaccount import providers | ||
from allauth.socialaccount.providers.base import ProviderAccount | ||
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider | ||
|
||
|
||
class LineAccount(ProviderAccount): | ||
|
||
def get_avatar_url(self): | ||
return self.account.extra_data.get('pictureUrl') | ||
|
||
def to_str(self): | ||
return self.account.extra_data.get('displayName', self.account.uid) | ||
|
||
|
||
class LineProvider(OAuth2Provider): | ||
id = 'line' | ||
name = 'Line' | ||
account_class = LineAccount | ||
|
||
def get_default_scope(self): | ||
return [] | ||
|
||
def extract_uid(self, data): | ||
return str(data['mid']) | ||
|
||
|
||
providers.registry.register(LineProvider) |
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,17 @@ | ||
from allauth.socialaccount.tests import OAuth2TestsMixin | ||
from allauth.tests import MockedResponse, TestCase | ||
|
||
from .provider import LineProvider | ||
|
||
|
||
class LineTests(OAuth2TestsMixin, TestCase): | ||
provider_id = LineProvider.id | ||
|
||
def get_mocked_response(self): | ||
return MockedResponse(200, """ | ||
{ | ||
"mid": "u7d47d26a6bab09b95695ff02d1a36e38", | ||
"displayName": "\uc774\uc0c1\ud601", | ||
"pictureUrl": | ||
"http://dl.profile.line-cdn.net/0m055ab14d725138288331268c45ac5286a35482fb794a" | ||
}""") |
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 LineProvider | ||
|
||
urlpatterns = default_urlpatterns(LineProvider) |
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 @@ | ||
import requests | ||
|
||
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter, | ||
OAuth2LoginView, | ||
OAuth2CallbackView) | ||
from .provider import LineProvider | ||
|
||
|
||
class LineOAuth2Adapter(OAuth2Adapter): | ||
provider_id = LineProvider.id | ||
access_token_url = 'https://api.line.me/v1/oauth/accessToken' | ||
authorize_url = 'https://access.line.me/dialog/oauth/weblogin' | ||
profile_url = 'https://api.line.me/v1/profile' | ||
|
||
def complete_login(self, request, app, token, **kwargs): | ||
headers = {'Authorization': 'Bearer {0}'.format(token.token)} | ||
resp = requests.get(self.profile_url, headers=headers) | ||
extra_data = resp.json() | ||
return self.get_provider().sociallogin_from_response(request, | ||
extra_data) | ||
|
||
|
||
oauth2_login = OAuth2LoginView.adapter_view(LineOAuth2Adapter) | ||
oauth2_callback = OAuth2CallbackView.adapter_view(LineOAuth2Adapter) |
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