[Python-modules-commits] [python-social-auth] 175/322: Create vend.py

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:13:05 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 f9597b9d0796dc555517fcd4d6cf67d9a7f76e9c
Author: Matt Howland <matt.howland at lab45.com>
Date:   Thu Mar 12 13:38:30 2015 -0700

    Create vend.py
---
 social/backends/vend.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/social/backends/vend.py b/social/backends/vend.py
new file mode 100644
index 0000000..013ca33
--- /dev/null
+++ b/social/backends/vend.py
@@ -0,0 +1,84 @@
+"""
+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 = ' '
+    REDIRECT_STATE = False
+    REDIRECT_URI_PARAMETER_NAME = 'redirect_uri'
+    EXTRA_DATA = [
+                     ('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
+
+
+
+
+    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()
+        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)
+        }
+
+    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)

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