~ubuntu-branches/debian/sid/social-auth-core/sid

« back to all changes in this revision

Viewing changes to social_core/backends/kakao.py

  • Committer: Package Import Robot
  • Author(s): Andre Bianchi
  • Date: 2018-02-22 19:49:12 UTC
  • Revision ID: package-import@ubuntu.com-20180222194912-4lqv8mlhnqc4ncd3
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Kakao OAuth2 backend, docs at:
 
3
    https://python-social-auth.readthedocs.io/en/latest/backends/kakao.html
 
4
"""
 
5
from .oauth import BaseOAuth2
 
6
 
 
7
 
 
8
class KakaoOAuth2(BaseOAuth2):
 
9
    """Kakao OAuth authentication backend"""
 
10
    name = 'kakao'
 
11
    AUTHORIZATION_URL = 'https://kauth.kakao.com/oauth/authorize'
 
12
    ACCESS_TOKEN_URL = 'https://kauth.kakao.com/oauth/token'
 
13
    ACCESS_TOKEN_METHOD = 'POST'
 
14
    REDIRECT_STATE = False
 
15
 
 
16
    def get_user_id(self, details, response):
 
17
        return response['id']
 
18
 
 
19
    def get_user_details(self, response):
 
20
        """Return user details from Kakao account"""
 
21
        nickname = response['properties']['nickname']
 
22
        return {
 
23
            'username': nickname,
 
24
            'email': '',
 
25
            'fullname': '',
 
26
            'first_name': '',
 
27
            'last_name': ''
 
28
        }
 
29
 
 
30
    def user_data(self, access_token, *args, **kwargs):
 
31
        """Loads user data from service"""
 
32
        return self.get_json('https://kapi.kakao.com/v1/user/me',
 
33
                             params={'access_token': access_token})
 
34
 
 
35
    def auth_complete_params(self, state=None):
 
36
        return {
 
37
            'grant_type': 'authorization_code',
 
38
            'code': self.data.get('code', ''),
 
39
            'client_id': self.get_key_and_secret()[0],
 
40
        }