[Python-modules-commits] [python-social-auth] 01/322: Salesforce OAuth2 support

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:12:41 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.10
in repository python-social-auth.

commit 1b808cf1280f503b4fdff779d0d606b05639b4ee
Author: Michal Karzyński <bitbucket at karzyn.com>
Date:   Wed Oct 8 22:17:34 2014 +0200

    Salesforce OAuth2 support
---
 social/backends/salesforce.py | 49 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/social/backends/salesforce.py b/social/backends/salesforce.py
new file mode 100644
index 0000000..5ca77e2
--- /dev/null
+++ b/social/backends/salesforce.py
@@ -0,0 +1,49 @@
+from urllib import urlencode
+from social.backends.oauth import BaseOAuth2
+
+
+class SalesforceOAuth2(BaseOAuth2):
+    """Salesforce OAuth2 authentication backend"""
+    name = 'salesforce-oauth2'
+    AUTHORIZATION_URL = 'https://login.salesforce.com/services/oauth2/authorize'
+    ACCESS_TOKEN_URL = 'https://login.salesforce.com/services/oauth2/token'
+    REVOKE_TOKEN_URL = 'https://login.salesforce.com/services/oauth2/revoke'
+    ACCESS_TOKEN_METHOD = 'POST'
+    REFRESH_TOKEN_METHOD = 'POST'
+    SCOPE_SEPARATOR = ' '
+    EXTRA_DATA = [
+        ('id', 'id'),
+        ('instance_url', 'instance_url'),
+        ('issued_at', 'issued_at'),
+        ('signature', 'signature'),
+        ('refresh_token', 'refresh_token'),
+        ]
+
+    def get_user_details(self, response):
+        """Return user details from a Salesforce account"""
+        return {
+            'username': response.get('username'),
+            'email': response.get('email') or '',
+            'first_name': response.get('first_name'),
+            'last_name': response.get('last_name'),
+            'fullname': response.get('display_name')
+        }
+
+    def user_data(self, access_token, *args, **kwargs):
+        """Loads user data from service"""
+        user_id_url = kwargs.get('response').get('id')
+        url = user_id_url + '?' + urlencode({
+            'access_token': access_token
+        })
+        try:
+            return self.get_json(url)
+        except ValueError:
+            return None
+
+
+class SalesforceOAuth2Sandbox(SalesforceOAuth2):
+    """Salesforce OAuth2 authentication testing backend"""
+    name = 'salesforce-oauth2-sandbox'
+    AUTHORIZATION_URL = 'https://test.salesforce.com/services/oauth2/authorize'
+    ACCESS_TOKEN_URL = 'https://test.salesforce.com/services/oauth2/token'
+    REVOKE_TOKEN_URL = 'https://test.salesforce.com/services/oauth2/revoke'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git



More information about the Python-modules-commits mailing list