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

« back to all changes in this revision

Viewing changes to social_core/backends/salesforce.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 six.moves.urllib_parse import urlencode
 
2
 
 
3
from .oauth import BaseOAuth2
 
4
 
 
5
 
 
6
class SalesforceOAuth2(BaseOAuth2):
 
7
    """Salesforce OAuth2 authentication backend"""
 
8
    name = 'salesforce-oauth2'
 
9
    AUTHORIZATION_URL = \
 
10
        'https://login.salesforce.com/services/oauth2/authorize'
 
11
    ACCESS_TOKEN_URL = 'https://login.salesforce.com/services/oauth2/token'
 
12
    REVOKE_TOKEN_URL = 'https://login.salesforce.com/services/oauth2/revoke'
 
13
    ACCESS_TOKEN_METHOD = 'POST'
 
14
    REFRESH_TOKEN_METHOD = 'POST'
 
15
    SCOPE_SEPARATOR = ' '
 
16
    EXTRA_DATA = [
 
17
        ('id', 'id'),
 
18
        ('instance_url', 'instance_url'),
 
19
        ('issued_at', 'issued_at'),
 
20
        ('signature', 'signature'),
 
21
        ('refresh_token', 'refresh_token'),
 
22
    ]
 
23
 
 
24
    def get_user_details(self, response):
 
25
        """Return user details from a Salesforce account"""
 
26
        return {
 
27
            'username': response.get('username'),
 
28
            'email': response.get('email') or '',
 
29
            'first_name': response.get('first_name'),
 
30
            'last_name': response.get('last_name'),
 
31
            'fullname': response.get('display_name')
 
32
        }
 
33
 
 
34
    def user_data(self, access_token, *args, **kwargs):
 
35
        """Loads user data from service"""
 
36
        user_id_url = kwargs.get('response').get('id')
 
37
        url = user_id_url + '?' + urlencode({'access_token': access_token})
 
38
        try:
 
39
            return self.get_json(url)
 
40
        except ValueError:
 
41
            return None
 
42
 
 
43
 
 
44
class SalesforceOAuth2Sandbox(SalesforceOAuth2):
 
45
    """Salesforce OAuth2 authentication testing backend"""
 
46
    name = 'salesforce-oauth2-sandbox'
 
47
    AUTHORIZATION_URL = 'https://test.salesforce.com/services/oauth2/authorize'
 
48
    ACCESS_TOKEN_URL = 'https://test.salesforce.com/services/oauth2/token'
 
49
    REVOKE_TOKEN_URL = 'https://test.salesforce.com/services/oauth2/revoke'