[Python-modules-commits] [python-social-auth] 95/322: NationBuilder backend

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 bb295abdc8abda7ad0b29288c87b7d0eed9e2610
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date:   Tue Feb 3 02:08:53 2015 -0200

    NationBuilder backend
---
 docs/backends/index.rst          |  1 +
 docs/backends/nationbuilder.rst  | 30 +++++++++++++++++++++++++
 social/backends/nationbuilder.py | 48 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)

diff --git a/docs/backends/index.rst b/docs/backends/index.rst
index 262d68f..6af6473 100644
--- a/docs/backends/index.rst
+++ b/docs/backends/index.rst
@@ -86,6 +86,7 @@ Social backends
    mineid
    mixcloud
    moves
+   nationbuilder
    odnoklassnikiru
    openstreetmap
    persona
diff --git a/docs/backends/nationbuilder.rst b/docs/backends/nationbuilder.rst
new file mode 100644
index 0000000..a27c3ec
--- /dev/null
+++ b/docs/backends/nationbuilder.rst
@@ -0,0 +1,30 @@
+NationBuilder
+=============
+
+`NationBuilder supports OAuth2`_ as their authentication mechanism. Follow these
+steps in order to use it:
+
+- Register a new application at your `Nation Admin panel`_ (define the `Callback
+  URL` to ``http://example.com/complete/nationbuilder/`` where ``example.com``
+  is your domain).
+
+- Fill the ``Client ID`` and ``Client Secret`` values from the newly created
+  application::
+
+    SOCIAL_AUTH_NATIONBUILDER_KEY = ''
+    SOCIAL_AUTH_NATIONBUILDER_SECRET = ''
+
+- Also define your NationBuilder slug::
+
+    SOCIAL_AUTH_NATIONBUILDER_SLUG = 'your-nationbuilder-slug'
+
+- Enable the backend in ``AUTHENTICATION_BACKENDS`` setting::
+
+    AUTHENTICATION_BACKENDS = (
+        ...
+        'social.backends.nationbuilder.NationBuilderOAuth2'
+        ...
+    )
+
+.. _Nation Admin panel: https://psa.nationbuilder.com/admin/apps
+.. _NationBuilder supports OAuth2: http://nationbuilder.com/api_quickstart
diff --git a/social/backends/nationbuilder.py b/social/backends/nationbuilder.py
new file mode 100644
index 0000000..ae16c7f
--- /dev/null
+++ b/social/backends/nationbuilder.py
@@ -0,0 +1,48 @@
+"""
+NationBuilder OAuth2 backend, docs at:
+    http://psa.matiasaguirre.net/docs/backends/nationbuilder.html
+"""
+from social.backends.oauth import BaseOAuth2
+
+
+class NationBuilderOAuth2(BaseOAuth2):
+    """NationBuilder OAuth2 authentication backend"""
+    name = 'nationbuilder'
+    AUTHORIZATION_URL = 'https://{slug}.nationbuilder.com/oauth/authorize'
+    ACCESS_TOKEN_URL = 'https://{slug}.nationbuilder.com/oauth/token'
+    ACCESS_TOKEN_METHOD = 'POST'
+    REDIRECT_STATE = False
+    SCOPE_SEPARATOR = ','
+    EXTRA_DATA = [
+        ('id', 'id'),
+        ('expires', 'expires')
+    ]
+
+    def authorization_url(self):
+        return self.AUTHORIZATION_URL.format(slug=self.slug)
+
+    def access_token_url(self):
+        return self.ACCESS_TOKEN_URL.format(slug=self.slug)
+
+    @property
+    def slug(self):
+        return self.setting('SLUG')
+
+    def get_user_details(self, response):
+        """Return user details from Github account"""
+        email = response.get('email') or ''
+        username = email.split('@')[0] if email else ''
+        return {'username': username,
+                'email': email,
+                'fullname': response.get('full_name') or '',
+                'first_name': response.get('first_name') or '',
+                'last_name': response.get('last_name') or ''}
+
+    def user_data(self, access_token, *args, **kwargs):
+        """Loads user data from service"""
+        url = 'https://{slug}.nationbuilder.com/api/v1/people/me'.format(
+            slug=self.slug
+        )
+        return self.get_json(url, params={
+            'access_token': access_token
+        })['person']

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