File: behance.py

package info (click to toggle)
python-social-auth 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,828 kB
  • ctags: 3,245
  • sloc: python: 12,867; makefile: 119; sh: 3
file content (39 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Behance OAuth2 backend, docs at:
    http://psa.matiasaguirre.net/docs/backends/behance.html
"""
from social.backends.oauth import BaseOAuth2


class BehanceOAuth2(BaseOAuth2):
    """Behance OAuth authentication backend"""
    name = 'behance'
    AUTHORIZATION_URL = 'https://www.behance.net/v2/oauth/authenticate'
    ACCESS_TOKEN_URL = 'https://www.behance.net/v2/oauth/token'
    ACCESS_TOKEN_METHOD = 'POST'
    SCOPE_SEPARATOR = '|'
    EXTRA_DATA = [('username', 'username')]
    REDIRECT_STATE = False

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

    def get_user_details(self, response):
        """Return user details from Behance account"""
        user = response['user']
        fullname, first_name, last_name = self.get_user_names(
            user['display_name'], user['first_name'], user['last_name']
        )
        return {'username': user['username'],
                'fullname': fullname,
                'first_name': first_name,
                'last_name': last_name,
                'email': ''}

    def extra_data(self, user, uid, response, details):
        # Pull up the embedded user attributes so they can be found as extra
        # data. See the example token response for possible attributes:
        # http://www.behance.net/dev/authentication#step-by-step
        data = response.copy()
        data.update(response['user'])
        return super(BehanceOAuth2, self).extra_data(user, uid, data, details)