Skip to content

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

@ffurrer

Description

@ffurrer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions