Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kakao backend #261

Merged
merged 1 commit into from
May 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/backends/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Social backends
google
instagram
jawbone
kakao
lastfm
linkedin
livejournal
Expand Down
17 changes: 17 additions & 0 deletions docs/backends/kakao.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Kakao
======

Kakao uses OAuth v2 for Authentication.

- Register a new applicationat the `Kakao API`_, and

- Fill ``Client Id`` and ``Client Secret`` values in the settings::

SOCIAL_AUTH_KAKAO_KEY = ''
SOCIAL_AUTH_KAKAO_SECRET = ''

- Also it's possible to define extra permissions with::

SOCIAL_AUTH_KAKAO_SCOPE = [...]

.. _Kakao API: https://developers.kakao.com/
2 changes: 2 additions & 0 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ or extend current one):
* Github_ OAuth2
* Google_ OAuth1, OAuth2 and OpenId
* Instagram_ OAuth2
* Kakao_ OAuth2
* Linkedin_ OAuth1
* Live_ OAuth2
* Livejournal_ OpenId
Expand Down Expand Up @@ -126,6 +127,7 @@ section.
.. _Github: https://github.com
.. _Google: http://google.com
.. _Instagram: https://instagram.com
.. _Kakao: https://kakao.com
.. _Linkedin: https://www.linkedin.com
.. _Live: https://www.live.com
.. _Livejournal: http://livejournal.com
Expand Down
34 changes: 34 additions & 0 deletions social/backends/kakao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Kakao OAuth2 backend, docs at:
http://psa.matiasaguirre.net/docs/backends/kakao.html
"""
from social.backends.oauth import BaseOAuth2


class KakaoOAuth2(BaseOAuth2):
"""Kakao OAuth authentication backend"""
name = 'kakao'
AUTHORIZATION_URL = 'https://kauth.kakao.com/oauth/authorize'
ACCESS_TOKEN_URL = 'https://kauth.kakao.com/oauth/token'
ACCESS_TOKEN_METHOD = 'POST'

def get_user_id(self, details, response):
return response['id']

def get_user_details(self, response):
"""Return user details from Kakao account"""
nickname = response['properties']['nickname']
thumbnail_image = response['properties']['thumbnail_image']
profile_image = response['properties']['profile_image']
return {
'username': nickname,
'email': '',
'fullname': '',
'first_name': '',
'last_name': ''
}

def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json('https://kapi.kakao.com/v1/user/me',
params={'access_token': access_token})
26 changes: 26 additions & 0 deletions social/tests/backends/test_kakao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json

from social.tests.backends.oauth import OAuth2Test


class KakaoOAuth2Test(OAuth2Test):
backend_path = 'social.backends.kakao.KakaoOAuth2'
user_data_url = 'https://kapi.kakao.com/v1/user/me'
expected_username = 'foobar'
access_token_body = json.dumps({
'access_token': 'foobar'
})
user_data_body = json.dumps({
'id': '101010101',
'properties': {
'nickname': 'foobar',
'thumbnail_image': 'http://mud-kage.kakao.co.kr/14/dn/btqbh1AKmRf/ujlHpQhxtMSbhKrBisrxe1/o.jpg',
'profile_image': 'http://mud-kage.kakao.co.kr/14/dn/btqbjCnl06Q/wbMJSVAUZB7lzSImgGdsoK/o.jpg'
}
})

def test_login(self):
self.do_login()

def test_partial_pipeline(self):
self.do_partial_pipeline()