Skip to content

Instantly share code, notes, and snippets.

@cchurch
Created November 12, 2015 20:39
Show Gist options
  • Save cchurch/5534eca95bd7364011dc to your computer and use it in GitHub Desktop.
Save cchurch/5534eca95bd7364011dc to your computer and use it in GitHub Desktop.
Custom Python social auth pipeline functions to fetch a GitHub user's orgs # and teams.
# Custom Python social auth pipeline functions to fetch a GitHub user's orgs
# and teams.
def fetch_github_user_orgs(backend, details, user=None, *args, **kwargs):
if not user or not hasattr(backend, 'get_json'):
return
response = kwargs.get('response') or {}
if 'organizations_url' not in response or 'access_token' not in response:
return
orgs = backend.get_json(response['organizations_url'],
params={'access_token': response['access_token']})
return {'organizations': orgs}
def fetch_github_user_teams(backend, details, user=None, *args, **kwargs):
import urlparse
if not user or not hasattr(backend, 'get_json'):
return
response = kwargs.get('response') or {}
if 'organizations_url' not in response or 'access_token' not in response:
return
teams_url = urlparse.urljoin(response['organizations_url'], '/user/teams')
teams = backend.get_json(teams_url,
params={'access_token': response['access_token']})
return {'teams': teams}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment