File: clef.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 (44 lines) | stat: -rw-r--r-- 1,551 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
40
41
42
43
44
"""
Clef OAuth support.

This contribution adds support for Clef OAuth service. The settings
SOCIAL_AUTH_CLEF_KEY and SOCIAL_AUTH_CLEF_SECRET must be defined with the
values given by Clef application registration process.
"""

from social.backends.oauth import BaseOAuth2


class ClefOAuth2(BaseOAuth2):
    """Clef OAuth authentication backend"""
    name = 'clef'
    AUTHORIZATION_URL = 'https://clef.io/iframes/qr'
    ACCESS_TOKEN_URL = 'https://clef.io/api/v1/authorize'
    ACCESS_TOKEN_METHOD = 'POST'
    SCOPE_SEPARATOR = ','

    def auth_params(self, *args, **kwargs):
        params = super(ClefOAuth2, self).auth_params(*args, **kwargs)
        params['app_id'] = params.pop('client_id')
        params['redirect_url'] = params.pop('redirect_uri')
        return params

    def get_user_details(self, response):
        """Return user details from Github account"""
        info = response.get('info')
        fullname, first_name, last_name = self.get_user_names(
            first_name=info.get('first_name'),
            last_name=info.get('last_name')
        )
        return {
            'username': response.get('clef_id'),
            'email': info.get('email', ''),
            'fullname': fullname,
            'first_name': first_name,
            'last_name': last_name,
            'phone_number': info.get('phone_number', '')
        }

    def user_data(self, access_token, *args, **kwargs):
        return self.get_json('https://clef.io/api/v1/info',
                             params={'access_token': access_token})