'This function is called once the OAuth2 workflow is complete. We
override this function to:
1. Inject `return_data` and `realm_admin` kwargs. These will
be used by `authenticate()` function to make the decision.
2. Call the proper `do_auth` function depending on whether
we are doing individual, team or organization based GitHub
authentication.
The actual decision on authentication is done in
SocialAuthMixin._common_authenticate().'

def do_auth(self, *args, **kwargs):

    kwargs['return_data'] = {}
    request = self.strategy.request
    kwargs['realm_subdomain'] = get_subdomain(request)
    user_profile = None
    team_id = settings.SOCIAL_AUTH_GITHUB_TEAM_ID
    org_name = settings.SOCIAL_AUTH_GITHUB_ORG_NAME
    if ((team_id is None) and (org_name is None)):
        try:
            user_profile = GithubOAuth2.do_auth(self, *args, **kwargs)
        except AuthFailed:
            logging.info('User    authentication    failed.')
            user_profile = None
    elif team_id:
        backend = GithubTeamOAuth2(self.strategy, self.redirect_uri)
        try:
            user_profile = backend.do_auth(*args, **kwargs)
        except AuthFailed:
            logging.info('User    is    not    member    of    GitHub    team.')
            user_profile = None
    elif org_name:
        backend = GithubOrganizationOAuth2(self.strategy, self.redirect_uri)
        try:
            user_profile = backend.do_auth(*args, **kwargs)
        except AuthFailed:
            logging.info('User    is    not    member    of    GitHub    organization.')
            user_profile = None
    return self.process_do_auth(user_profile, *args, **kwargs)
