2
NationBuilder OAuth2 backend, docs at:
3
https://python-social-auth.readthedocs.io/en/latest/backends/nationbuilder.html
5
from .oauth import BaseOAuth2
8
class NationBuilderOAuth2(BaseOAuth2):
9
"""NationBuilder OAuth2 authentication backend"""
10
name = 'nationbuilder'
11
AUTHORIZATION_URL = 'https://{slug}.nationbuilder.com/oauth/authorize'
12
ACCESS_TOKEN_URL = 'https://{slug}.nationbuilder.com/oauth/token'
13
ACCESS_TOKEN_METHOD = 'POST'
14
REDIRECT_STATE = False
18
('expires', 'expires')
21
def authorization_url(self):
22
return self.AUTHORIZATION_URL.format(slug=self.slug)
24
def access_token_url(self):
25
return self.ACCESS_TOKEN_URL.format(slug=self.slug)
29
return self.setting('SLUG')
31
def get_user_details(self, response):
32
"""Return user details from Github account"""
33
email = response.get('email') or ''
34
username = email.split('@')[0] if email else ''
35
return {'username': username,
37
'fullname': response.get('full_name') or '',
38
'first_name': response.get('first_name') or '',
39
'last_name': response.get('last_name') or ''}
41
def user_data(self, access_token, *args, **kwargs):
42
"""Loads user data from service"""
43
url = 'https://{slug}.nationbuilder.com/api/v1/people/me'.format(
46
return self.get_json(url, params={
47
'access_token': access_token