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 doesn't select Primary Email #413

Closed
abourget opened this issue Oct 9, 2014 · 1 comment
Closed

GitHub doesn't select Primary Email #413

abourget opened this issue Oct 9, 2014 · 1 comment

Comments

@abourget
Copy link

abourget commented Oct 9, 2014

I've got 7 emails in my GitHub account.. but I selected one as my primary. python-social-auth just takes the first one in the provided list, disregarding my selection. I have stale e-mails in there.. Think we could pick the primary e-mail!

This was an attempt to monkey patch django-social-auth with the intended behavior. If there's interest, I can make it a PR in python-social-auth:

# re-implements: backends/contrib/github.py:L57-66
def _fetch_emails_replacement(self, access_token):
    """Fetch private emails from Github account

    Github returns something like:

    [
      {
        "email": "octocat@github.com",
        "verified": true,
        "primary": true
      }
    ]

    """
    url = GITHUB_USER_DATA_URL + '/emails?' + urlencode({
        'access_token': access_token
    })

    try:
        data = simplejson.load(dsa_urlopen(url))
    except (ValueError, HTTPError):
        return []

    emails = [x['email'] for x in data
              if x['primary']]
    if emails:
        return [emails[0]]
    else:
        if data:
            return [data[0]['email']]
        else:
            return []

github.GithubBackend._fetch_emails = _fetch_emails_replacement
@omab omab closed this as completed in 6550eae Oct 23, 2014
@omab
Copy link
Owner

omab commented Oct 23, 2014

I've introduced a change to give github primary emails priority.

amegianeg pushed a commit to docker-archive/python-social-auth that referenced this issue Jan 26, 2015
Conflicts:
	social/backends/github.py
amegianeg pushed a commit to docker-archive/python-social-auth that referenced this issue Jan 26, 2015
Pick github primary email first. Fixes omab#413
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