[Python-modules-commits] [python-social-auth] 96/322: Move common code to base class
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:12:53 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 71c1028811cd82102518a1aaf0ca87ec6d7265ea
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date: Tue Feb 3 02:36:20 2015 -0200
Move common code to base class
---
social/backends/oauth.py | 42 ++++++++++++++++++++----------------------
social/tests/backends/oauth.py | 5 ++---
2 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/social/backends/oauth.py b/social/backends/oauth.py
index 0e33a04..717092d 100644
--- a/social/backends/oauth.py
+++ b/social/backends/oauth.py
@@ -20,14 +20,20 @@ class OAuthAuth(BaseAuth):
name (all uppercase) plus _EXTRA_DATA.
access_token is always stored.
+
+ URLs settings:
+ AUTHORIZATION_URL Authorization service url
+ ACCESS_TOKEN_URL Access token URL
"""
- SCOPE_PARAMETER_NAME = 'scope'
- DEFAULT_SCOPE = None
- SCOPE_SEPARATOR = ' '
- ID_KEY = 'id'
+ AUTHORIZATION_URL = ''
+ ACCESS_TOKEN_URL = ''
ACCESS_TOKEN_METHOD = 'GET'
REVOKE_TOKEN_URL = None
REVOKE_TOKEN_METHOD = 'POST'
+ ID_KEY = 'id'
+ SCOPE_PARAMETER_NAME = 'scope'
+ DEFAULT_SCOPE = None
+ SCOPE_SEPARATOR = ' '
REDIRECT_STATE = False
STATE_PARAMETER = False
@@ -109,6 +115,12 @@ class OAuthAuth(BaseAuth):
"""Loads user data from service. Implement in subclass"""
return {}
+ def authorization_url(self):
+ return self.AUTHORIZATION_URL
+
+ def access_token_url(self):
+ return self.ACCESS_TOKEN_URL
+
def revoke_token_url(self, token, uid):
return self.REVOKE_TOKEN_URL
@@ -137,16 +149,14 @@ class BaseOAuth1(OAuthAuth):
"""Consumer based mechanism OAuth authentication, fill the needed
parameters to communicate properly with authentication service.
- AUTHORIZATION_URL Authorization service url
+ URLs settings:
REQUEST_TOKEN_URL Request token URL
- ACCESS_TOKEN_URL Access token URL
+
"""
- AUTHORIZATION_URL = ''
REQUEST_TOKEN_URL = ''
REQUEST_TOKEN_METHOD = 'GET'
OAUTH_TOKEN_PARAMETER_NAME = 'oauth_token'
REDIRECT_URI_PARAMETER_NAME = 'redirect_uri'
- ACCESS_TOKEN_URL = ''
UNATHORIZED_TOKEN_SUFIX = 'unauthorized_token_name'
def auth_url(self):
@@ -252,7 +262,7 @@ class BaseOAuth1(OAuthAuth):
)
state = self.get_or_create_state()
params[self.REDIRECT_URI_PARAMETER_NAME] = self.get_redirect_uri(state)
- return self.AUTHORIZATION_URL + '?' + urlencode(params)
+ return '{0}?{1}'.format(self.authorization_url(), urlencode(params))
def oauth_auth(self, token=None, oauth_verifier=None,
signature_type=SIGNATURE_TYPE_AUTH_HEADER):
@@ -278,7 +288,7 @@ class BaseOAuth1(OAuthAuth):
def access_token(self, token):
"""Return request for access token value"""
- return self.get_querystring(self.ACCESS_TOKEN_URL,
+ return self.get_querystring(self.access_token_url(),
auth=self.oauth_auth(token),
method=self.ACCESS_TOKEN_METHOD)
@@ -288,13 +298,7 @@ class BaseOAuth2(OAuthAuth):
OAuth2 draft details at:
http://tools.ietf.org/html/draft-ietf-oauth-v2-10
-
- Attributes:
- AUTHORIZATION_URL Authorization service url
- ACCESS_TOKEN_URL Token URL
"""
- AUTHORIZATION_URL = None
- ACCESS_TOKEN_URL = None
REFRESH_TOKEN_URL = None
REFRESH_TOKEN_METHOD = 'POST'
RESPONSE_TYPE = 'code'
@@ -405,11 +409,5 @@ class BaseOAuth2(OAuthAuth):
request = self.request(url, **request_args)
return self.process_refresh_token_response(request, *args, **kwargs)
- def authorization_url(self):
- return self.AUTHORIZATION_URL
-
- def access_token_url(self):
- return self.ACCESS_TOKEN_URL
-
def refresh_token_url(self):
return self.REFRESH_TOKEN_URL or self.access_token_url()
diff --git a/social/tests/backends/oauth.py b/social/tests/backends/oauth.py
index 0169bd2..9b9c849 100644
--- a/social/tests/backends/oauth.py
+++ b/social/tests/backends/oauth.py
@@ -59,7 +59,7 @@ class BaseOAuthTest(BaseBackendTest):
status=200,
body='foobar')
HTTPretty.register_uri(self._method(self.backend.ACCESS_TOKEN_METHOD),
- uri=self.backend.ACCESS_TOKEN_URL,
+ uri=self.backend.access_token_url(),
status=self.access_token_status,
body=self.access_token_body or '',
content_type='text/json')
@@ -107,8 +107,7 @@ class OAuth2Test(BaseOAuthTest):
def do_refresh_token(self):
self.do_login()
HTTPretty.register_uri(self._method(self.backend.REFRESH_TOKEN_METHOD),
- self.backend.REFRESH_TOKEN_URL or
- self.backend.ACCESS_TOKEN_URL,
+ self.backend.refresh_token_url(),
status=200,
body=self.refresh_token_body)
user = list(User.cache.values())[0]
--
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