Created
November 12, 2015 20:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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