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

« back to all changes in this revision

Viewing changes to social_core/backends/amazon.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
Amazon OAuth2 backend, docs at:
 
3
    https://python-social-auth.readthedocs.io/en/latest/backends/amazon.html
 
4
"""
 
5
import ssl
 
6
 
 
7
from .oauth import BaseOAuth2
 
8
 
 
9
 
 
10
class AmazonOAuth2(BaseOAuth2):
 
11
    name = 'amazon'
 
12
    ID_KEY = 'user_id'
 
13
    AUTHORIZATION_URL = 'https://www.amazon.com/ap/oa'
 
14
    ACCESS_TOKEN_URL = 'https://api.amazon.com/auth/o2/token'
 
15
    DEFAULT_SCOPE = ['profile']
 
16
    REDIRECT_STATE = False
 
17
    ACCESS_TOKEN_METHOD = 'POST'
 
18
    SSL_PROTOCOL = ssl.PROTOCOL_TLSv1
 
19
    EXTRA_DATA = [
 
20
        ('refresh_token', 'refresh_token', True),
 
21
        ('user_id', 'user_id'),
 
22
        ('postal_code', 'postal_code')
 
23
    ]
 
24
 
 
25
    def get_user_details(self, response):
 
26
        """Return user details from amazon account"""
 
27
        name = response.get('name') or ''
 
28
        fullname, first_name, last_name = self.get_user_names(name)
 
29
        return {'username': name,
 
30
                'email': response.get('email'),
 
31
                'fullname': fullname,
 
32
                'first_name': first_name,
 
33
                'last_name': last_name}
 
34
 
 
35
    def user_data(self, access_token, *args, **kwargs):
 
36
        """Grab user profile information from amazon."""
 
37
        response = self.get_json('https://www.amazon.com/ap/user/profile',
 
38
                                 params={'access_token': access_token})
 
39
        if 'Profile' in response:
 
40
            response = {
 
41
                'user_id': response['Profile']['CustomerId'],
 
42
                'name': response['Profile']['Name'],
 
43
                'email': response['Profile']['PrimaryEmail']
 
44
            }
 
45
        return response