1
from six.moves.urllib_parse import urlencode
3
from .oauth import BaseOAuth2
6
class SalesforceOAuth2(BaseOAuth2):
7
"""Salesforce OAuth2 authentication backend"""
8
name = 'salesforce-oauth2'
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'
18
('instance_url', 'instance_url'),
19
('issued_at', 'issued_at'),
20
('signature', 'signature'),
21
('refresh_token', 'refresh_token'),
24
def get_user_details(self, response):
25
"""Return user details from a Salesforce account"""
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')
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})
39
return self.get_json(url)
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'