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

« back to all changes in this revision

Viewing changes to social_core/backends/eventbrite.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
from .oauth import BaseOAuth2
 
2
 
 
3
 
 
4
class EventbriteOAuth2(BaseOAuth2):
 
5
    """Eventbrite OAuth2 authentication backend"""
 
6
    name = 'eventbrite'
 
7
    AUTHORIZATION_URL = 'https://www.eventbrite.com/oauth/authorize'
 
8
    ACCESS_TOKEN_URL = 'https://www.eventbrite.com/oauth/token'
 
9
    METADATA_URL = 'https://www.eventbriteapi.com/v3/users/me'
 
10
    ACCESS_TOKEN_METHOD = 'POST'
 
11
    STATE_PARAMETER = False
 
12
    REDIRECT_STATE = False
 
13
 
 
14
    def get_user_details(self, response):
 
15
        """Return user details from an Eventbrite metadata response"""
 
16
        email = next(iter(filter(lambda x: x['primary'], response['emails'])))['email']
 
17
 
 
18
        return {
 
19
            'username': email,
 
20
            'email': email,
 
21
            'first_name': response['first_name'],
 
22
            'last_name': response['last_name']
 
23
        }
 
24
 
 
25
    def user_data(self, access_token, *args, **kwargs):
 
26
        """Loads user data and datacenter information from service"""
 
27
        return self.get_json(self.METADATA_URL, headers={
 
28
          'Authorization': 'Bearer ' + access_token
 
29
        })