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

« back to all changes in this revision

Viewing changes to social_core/backends/trello.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
Trello OAuth1 backend, docs at:
 
3
    https://python-social-auth.readthedocs.io/en/latest/backends/trello.html
 
4
"""
 
5
from .oauth import BaseOAuth1
 
6
 
 
7
 
 
8
class TrelloOAuth(BaseOAuth1):
 
9
 
 
10
    """Trello OAuth authentication backend"""
 
11
    name = 'trello'
 
12
    ID_KEY = 'username'
 
13
    AUTHORIZATION_URL = 'https://trello.com/1/OAuthAuthorizeToken'
 
14
    REQUEST_TOKEN_URL = 'https://trello.com/1/OAuthGetRequestToken'
 
15
    ACCESS_TOKEN_URL = 'https://trello.com/1/OAuthGetAccessToken'
 
16
 
 
17
    EXTRA_DATA = [
 
18
        ('username', 'username'),
 
19
        ('email', 'email'),
 
20
        ('fullName', 'fullName')
 
21
    ]
 
22
 
 
23
    def get_user_details(self, response):
 
24
        """Return user details from Trello account"""
 
25
        fullname, first_name, last_name = self.get_user_names(
 
26
            response.get('fullName')
 
27
        )
 
28
        return {'username': response.get('username'),
 
29
                'email': response.get('email'),
 
30
                'fullname': fullname,
 
31
                'first_name': first_name,
 
32
                'last_name': last_name}
 
33
 
 
34
    def user_data(self, access_token):
 
35
        """Return user data provided"""
 
36
        url = 'https://trello.com/1/members/me'
 
37
        try:
 
38
            return self.get_json(url, auth=self.oauth_auth(access_token))
 
39
        except ValueError:
 
40
            return None
 
41
 
 
42
    def auth_extra_arguments(self):
 
43
        return {
 
44
            'name': self.setting('APP_NAME', ''),
 
45
            # trello default expiration is '30days'
 
46
            'expiration': self.setting('EXPIRATION', 'never')
 
47
        }