Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github support for checking if a user is part of a team #329

Closed
ffurrer opened this issue Jul 16, 2014 · 3 comments
Closed

Github support for checking if a user is part of a team #329

ffurrer opened this issue Jul 16, 2014 · 3 comments

Comments

@ffurrer
Copy link

ffurrer commented Jul 16, 2014

I suggest adding something like this to check if a github user is part of a team (similar to check if a user is part of an organization.

GITHUB_TEAM_MEMBER_OF_URL = 'https://api.github.com/teams/{team_id}/members/{username}'

And then something like this:

# If we have a github team id defined, test that the current user
# is a member of that team.
if data and self.GITHUB_TEAM_ID:
    member_url = GITHUB_TEAM_MEMBER_OF_URL.format(
        username=data.get('login'),
        team_id=self.GITHUB_TEAM_ID,
    ) + '?' + urlencode({
        'access_token': access_token
    })
    try:
        response = dsa_urlopen(member_url)
    except HTTPError:
        raise AuthFailed(self, 'User doesn\'t belong to the team')
    else:
        if response.code != 204:
            raise AuthFailed('User doesn\'t belong to the team')

I created a working solution with the above code for django-social-auth==0.7.28. If there are more 0.7.* versions planned please add it there as well.

@ffurrer
Copy link
Author

ffurrer commented Jul 16, 2014

And here's my branch, I'm not super happy with the implementation but I just adapted from the other code.
https://github.com/ffurrer/django-social-auth/tree/feature/github_team_support

omab added a commit that referenced this issue Jul 19, 2014
@omab
Copy link
Owner

omab commented Jul 19, 2014

@ffurrer, I've added an extra github backend, similar to the github-for-organizations backend, but that checks by team instead, the code was so similar that I've added a class to deal with the common code.

Thanks

@omab omab closed this as completed Jul 19, 2014
@ffurrer
Copy link
Author

ffurrer commented Jul 22, 2014

nice, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants