Statistics
| Branch: | Tag: | Revision:

root / social / backends / pixelpin.py @ a0a04c0a

History | View | Annotate | Download (1.2 kB)

1
from social.backends.oauth import BaseOAuth2
2

    
3

    
4
class PixelPinOAuth2(BaseOAuth2):
5
    """PixelPin OAuth authentication backend"""
6
    name = 'pixelpin-oauth2'
7
    ID_KEY = 'id'
8
    AUTHORIZATION_URL = 'https://login.pixelpin.co.uk/OAuth2/Flogin.aspx'
9
    ACCESS_TOKEN_URL = 'https://ws3.pixelpin.co.uk/index.php/api/token'
10
    ACCESS_TOKEN_METHOD = 'POST'
11
    REQUIRES_EMAIL_VALIDATION = False
12
    EXTRA_DATA = [
13
        ('id', 'id'),
14
    ]
15

    
16
    def get_user_details(self, response):
17
        """Return user details from PixelPin account"""
18
        fullname, first_name, last_name = self.get_user_names(
19
            first_name=response.get('firstName'),
20
            last_name=response.get('lastName')
21
        )
22
        return {'username': response.get('firstName'),
23
                'email': response.get('email') or '',
24
                'fullname': fullname,
25
                'first_name': first_name,
26
                'last_name': last_name}
27

    
28
    def user_data(self, access_token, *args, **kwargs):
29
        """Loads user data from service"""
30
        return self.get_json(
31
            'https://ws3.pixelpin.co.uk/index.php/api/userdata',
32
            params={'access_token': access_token}
33
        )