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

« back to all changes in this revision

Viewing changes to social_core/backends/foursquare.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
Foursquare OAuth2 backend, docs at:
 
3
    https://python-social-auth.readthedocs.io/en/latest/backends/foursquare.html
 
4
"""
 
5
from .oauth import BaseOAuth2
 
6
 
 
7
 
 
8
class FoursquareOAuth2(BaseOAuth2):
 
9
    name = 'foursquare'
 
10
    AUTHORIZATION_URL = 'https://foursquare.com/oauth2/authenticate'
 
11
    ACCESS_TOKEN_URL = 'https://foursquare.com/oauth2/access_token'
 
12
    ACCESS_TOKEN_METHOD = 'POST'
 
13
    API_VERSION = '20140128'
 
14
 
 
15
    def get_user_id(self, details, response):
 
16
        return response['response']['user']['id']
 
17
 
 
18
    def get_user_details(self, response):
 
19
        """Return user details from Foursquare account"""
 
20
        info = response['response']['user']
 
21
        email = info['contact']['email']
 
22
        fullname, first_name, last_name = self.get_user_names(
 
23
            first_name=info.get('firstName', ''),
 
24
            last_name=info.get('lastName', '')
 
25
        )
 
26
        return {'username': first_name + ' ' + last_name,
 
27
                'fullname': fullname,
 
28
                'first_name': first_name,
 
29
                'last_name': last_name,
 
30
                'email': email}
 
31
 
 
32
    def user_data(self, access_token, *args, **kwargs):
 
33
        """Loads user data from service"""
 
34
        return self.get_json('https://api.foursquare.com/v2/users/self',
 
35
                             params={'oauth_token': access_token,
 
36
                                     'v': self.API_VERSION})