[Python-modules-commits] [python-social-auth] 06/71: Added justgiving.com OAuth2 backend
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:14:21 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.14
in repository python-social-auth.
commit a93a07f78b1c939cfbcee9212ac02d508b04ebdf
Author: Michael Willmott <michael at knodium.com>
Date: Wed Sep 2 11:33:41 2015 +0100
Added justgiving.com OAuth2 backend
Signed-off-by: Michael Willmott <michael at knodium.com>
---
docs/backends/justgiving.rst | 20 +++++++++++++++
social/backends/justgiving.py | 57 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/docs/backends/justgiving.rst b/docs/backends/justgiving.rst
new file mode 100644
index 0000000..52ca301
--- /dev/null
+++ b/docs/backends/justgiving.rst
@@ -0,0 +1,20 @@
+Just Giving
+===========
+
+OAuth2
+------
+
+Add the Just Giving OAuth2 backend to your settings page::
+
+ SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
+ ...
+ 'social.backends.justgiving.JustGivingOAuth2',
+ ...
+ )
+
+- Fill ``App Key`` and ``App Secret`` values in the settings::
+
+ SOCIAL_AUTH_JUSTGIVING_KEY = ''
+ SOCIAL_AUTH_JUSTGIVING_SECRET = ''
+
+.. _Just Giving API Docs: https://api.justgiving.com/docs
diff --git a/social/backends/justgiving.py b/social/backends/justgiving.py
new file mode 100644
index 0000000..78f7fa2
--- /dev/null
+++ b/social/backends/justgiving.py
@@ -0,0 +1,57 @@
+from requests.auth import HTTPBasicAuth
+from social.utils import handle_http_errors
+from social.backends.oauth import BaseOAuth2
+
+
+class JustGivingOAuth2(BaseOAuth2):
+ """Just Giving OAuth authentication backend"""
+ name = 'justgiving'
+ ID_KEY = 'userId'
+ AUTHORIZATION_URL = 'https://identity.justgiving.com/connect/authorize'
+ ACCESS_TOKEN_URL = 'https://identity.justgiving.com/connect/token'
+ ACCESS_TOKEN_METHOD = 'POST'
+ USER_DATA_URL = 'https://api.justgiving.com/v1/account'
+ DEFAULT_SCOPE = ['openid', 'account', 'profile', 'email', 'fundraise']
+
+ def get_user_details(self, response):
+ """Return user details from Just Giving account"""
+ fullname, first_name, last_name = self.get_user_names(
+ '',
+ response.get('firstName'),
+ response.get('lastName'))
+ return {
+ 'username': response.get('email'),
+ 'email': response.get('email'),
+ 'fullname': fullname,
+ 'first_name': first_name,
+ 'last_name': last_name
+ }
+
+ def user_data(self, access_token, *args, **kwargs):
+ """Loads user data from service"""
+ key, secret = self.get_key_and_secret()
+ return self.get_json(
+ self.USER_DATA_URL,
+ headers={
+ 'Authorization': 'Bearer {0}'.format(access_token),
+ 'Content-Type': 'application/json',
+ 'x-application-key': secret,
+ 'x-api-key': key
+ })
+
+ @handle_http_errors
+ def auth_complete(self, *args, **kwargs):
+ """Completes loging process, must return user instance"""
+ state = self.validate_state()
+ self.process_error(self.data)
+
+ key, secret = self.get_key_and_secret()
+ response = self.request_access_token(
+ self.access_token_url(),
+ data=self.auth_complete_params(state),
+ headers=self.auth_headers(),
+ auth=HTTPBasicAuth(key, secret),
+ method=self.ACCESS_TOKEN_METHOD
+ )
+ self.process_error(response)
+ return self.do_auth(response['access_token'], response=response, *args, **kwargs)
\ No newline at end of file
--
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