Skip to content

Commit

Permalink
Add Line Provider (#1582)
Browse files Browse the repository at this point in the history
* Add Line Provider

* Modify Line Provider Test Code (MockedResponse)

* Fix line provider flake8 error

* modify test_settings.py, installation.rst
  • Loading branch information
shlee322 authored and pennersr committed Jan 14, 2017
1 parent 113187c commit 31a5f47
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -88,6 +88,7 @@ Rod Xavier Bondoc
Roman Tomjak
Roumen Antonov
Sam Solomon
Sanghyeok Lee
Seizan Shimazaki
Serafeim Papastefanos
Shane Rice
Expand Down
Empty file.
Empty file.
27 changes: 27 additions & 0 deletions allauth/socialaccount/providers/line/provider.py
@@ -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)
17 changes: 17 additions & 0 deletions allauth/socialaccount/providers/line/tests.py
@@ -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"
}""")
4 changes: 4 additions & 0 deletions allauth/socialaccount/providers/line/urls.py
@@ -0,0 +1,4 @@
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
from .provider import LineProvider

urlpatterns = default_urlpatterns(LineProvider)
24 changes: 24 additions & 0 deletions allauth/socialaccount/providers/line/views.py
@@ -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)
1 change: 1 addition & 0 deletions docs/installation.rst
Expand Up @@ -84,6 +84,7 @@ settings.py (Important - Please note 'django.contrib.sites' is required as INSTA
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.hubic',
'allauth.socialaccount.providers.instagram',
'allauth.socialaccount.providers.line',
'allauth.socialaccount.providers.linkedin',
'allauth.socialaccount.providers.linkedin_oauth2',
'allauth.socialaccount.providers.mailru',
Expand Down
2 changes: 2 additions & 0 deletions docs/overview.rst
Expand Up @@ -83,6 +83,8 @@ Supported Providers

- Instagram (OAuth2)

- Line (OAuth2)

- LinkedIn (OAuth, OAuth2)

- Mail.Ru (OAuth2)
Expand Down
10 changes: 10 additions & 0 deletions docs/providers.rst
Expand Up @@ -475,6 +475,16 @@ Development callback URL
http://localhost:8000/accounts/instagram/login/callback/


Line
----

App registration (get your key and secret here)
https://business.line.me

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


LinkedIn
--------

Expand Down
1 change: 1 addition & 0 deletions test_settings.py
Expand Up @@ -95,6 +95,7 @@
'allauth.socialaccount.providers.gitlab',
'allauth.socialaccount.providers.hubic',
'allauth.socialaccount.providers.instagram',
'allauth.socialaccount.providers.line',
'allauth.socialaccount.providers.linkedin',
'allauth.socialaccount.providers.linkedin_oauth2',
'allauth.socialaccount.providers.mailru',
Expand Down

0 comments on commit 31a5f47

Please sign in to comment.