[Python-modules-commits] [python-social-auth] 199/322: Fix backend, add quick docs. Refs #549

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:13:08 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 7267581f0acaef5830dfac18bfe075f2df82b224
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date:   Wed Mar 25 01:44:53 2015 -0300

    Fix backend, add quick docs. Refs #549
---
 docs/backends/index.rst                     |  1 +
 docs/backends/vend.rst                      | 24 ++++++++
 examples/django_example/example/settings.py |  1 +
 social/backends/vend.py                     | 87 +++++++----------------------
 4 files changed, 47 insertions(+), 66 deletions(-)

diff --git a/docs/backends/index.rst b/docs/backends/index.rst
index 0b4b3b4..0859a74 100644
--- a/docs/backends/index.rst
+++ b/docs/backends/index.rst
@@ -118,6 +118,7 @@ Social backends
    twilio
    twitch
    twitter
+   vend
    vimeo
    vk
    weibo
diff --git a/docs/backends/vend.rst b/docs/backends/vend.rst
new file mode 100644
index 0000000..880698e
--- /dev/null
+++ b/docs/backends/vend.rst
@@ -0,0 +1,24 @@
+Vend
+====
+
+Vend supports OAuth 2.
+
+- Register a new application at `Vend Developers Portal`_
+  
+- Add the Vend OAuth2 backend to your settings page::
+
+    SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
+        ...
+        'social.backends.vend.VendOAuth2',
+        ...
+    )
+
+- Fill ``App Key`` and ``App Secret`` values in the settings::
+
+      SOCIAL_AUTH_VEND_OAUTH2_KEY = ''
+      SOCIAL_AUTH_VEND_OAUTH2_SECRET = ''
+
+More details on their docs_.
+
+.. _Vend Developers Portal: https://developers.vendhq.com/developer/applications
+.. _docs: https://developers.vendhq.com/documentation
diff --git a/examples/django_example/example/settings.py b/examples/django_example/example/settings.py
index fff53dc..58ab9c7 100644
--- a/examples/django_example/example/settings.py
+++ b/examples/django_example/example/settings.py
@@ -198,6 +198,7 @@ AUTHENTICATION_BACKENDS = (
     'social.backends.vimeo.VimeoOAuth1',
     'social.backends.lastfm.LastFmAuth',
     'social.backends.moves.MovesOAuth2',
+    'social.backends.vend.VendOAuth2',
     'social.backends.email.EmailAuth',
     'social.backends.username.UsernameAuth',
     'django.contrib.auth.backends.ModelBackend',
diff --git a/social/backends/vend.py b/social/backends/vend.py
index 013ca33..5c3927a 100644
--- a/social/backends/vend.py
+++ b/social/backends/vend.py
@@ -1,84 +1,39 @@
 """
 Vend  OAuth2 backend:
-
 """
-from requests import HTTPError
 from social.backends.oauth import BaseOAuth2
-from social.exceptions import AuthCanceled, AuthUnknownError
 
 
 class VendOAuth2(BaseOAuth2):
     name = 'vend'
     AUTHORIZATION_URL = 'https://secure.vendhq.com/connect'
-    ACCESS_TOKEN_URL = ''
-    SCOPE_SEPARATOR = ' '
+    ACCESS_TOKEN_URL = 'https://{0}.vendhq.com/api/1.0/token'
+    ACCESS_TOKEN_METHOD = 'POST'
     REDIRECT_STATE = False
-    REDIRECT_URI_PARAMETER_NAME = 'redirect_uri'
     EXTRA_DATA = [
-                     ('refresh_token', 'refresh_token'),
-                     ('domain_prefix','domain_prefix')
+        ('refresh_token', 'refresh_token'),
+        ('domain_prefix', 'domain_prefix')
     ]
-    def get_user_id(self, details, response):
-        return None
-    def get_user_details(self, response):
-        return {}
-
-    def user_data(self, access_token, *args, **kwargs):
-
-        return None
-
 
     def access_token_url(self):
-        return self.ACCESS_TOKEN_URL
-
-
-
+        return self.ACCESS_TOKEN_URL.format(self.data['domain_prefix'])
 
-    def process_error(self, data):
-        error = data.get('error')
-        if error:
-            if error == 'access_denied':
-                raise AuthCanceled(self)
-            else:
-                raise AuthUnknownError(self, 'Vend error was {0}'.format(
-                    error
-                ))
-        return super(VendOAuth2, self).process_error(data)
-
-    def auth_complete_params(self, state=None):
-        client_id, client_secret = self.get_key_and_secret()
+    def get_user_details(self, response):
+        email = response['email']
+        username = response.get('username') or email.split('@', 1)[0]
         return {
-           'code': self.data.get('code', '').encode('ascii', 'ignore'),  # server response code
-            'client_id': client_id,
-            'client_secret': client_secret,
-            'grant_type': 'authorization_code',  # request auth code
-            'redirect_uri': self.get_redirect_uri(state)
+            'username': username,
+            'email': email,
+            'fullname': '',
+            'first_name': '',
+            'last_name': ''
         }
 
-    def auth_complete(self, *args, **kwargs):
-        """Completes loging process, must return user instance"""
-
-        #Handle dynamic login access_token_url
-        self.ACCESS_TOKEN_URL = 'https://{0}.vendhq.com/api/1.0/token'.format(self.data["domain_prefix"])
-
-        self.process_error(self.data)
-        try:
-            response = self.request_access_token(
-                self.ACCESS_TOKEN_URL,
-                params=self.auth_complete_params(self.validate_state()),
-                headers=self.auth_headers(),
-                method='POST',
-
-            )
-        except HTTPError as err:
-            if err.response.status_code == 400:
-                raise AuthCanceled(self)
-            else:
-
-                raise
-        except KeyError:
-            raise AuthUnknownError(self)
-        self.process_error(response)
-
-        return self.do_auth(response['access_token'], response=response,
-                            *args, **kwargs)
+    def user_data(self, access_token, *args, **kwargs):
+        """Loads user data from service"""
+        prefix = kwargs['response']['domain_prefix']
+        url = 'https://{0}.vendhq.com/api/users'.format(prefix)
+        data = self.get_json(url, headers={
+            'Authorization': 'Bearer {0}'.format(access_token)
+        })
+        return data['users'][0] if data.get('users') else {}

-- 
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