[Python-modules-commits] [python-social-auth] 06/322: Pick github primary email first. Fixes #413
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:12:42 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.10
in repository python-social-auth.
commit 6550eaee8ff94f4b2cb7dec7f704022796704612
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date: Thu Oct 23 01:23:48 2014 -0200
Pick github primary email first. Fixes #413
---
social/backends/github.py | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/social/backends/github.py b/social/backends/github.py
index 30f9812..db58cc1 100644
--- a/social/backends/github.py
+++ b/social/backends/github.py
@@ -36,13 +36,21 @@ class GithubOAuth2(BaseOAuth2):
data = self._user_data(access_token)
if not data.get('email'):
try:
- email = self._user_data(access_token, '/emails')[0]
- except (HTTPError, IndexError, ValueError, TypeError):
- email = ''
-
- if isinstance(email, dict):
- email = email.get('email', '')
- data['email'] = email
+ emails = self._user_data(access_token, '/emails')
+ except (HTTPError, ValueError, TypeError):
+ emails = []
+
+ if emails:
+ email = emails[0]
+ primary_emails = [e for e in emails
+ if not isinstance(e, dict) or
+ e.get('primary')]
+
+ if primary_emails:
+ email = primary_emails[0]
+ if isinstance(email, dict):
+ email = email.get('email', '')
+ data['email'] = email
return data
def _user_data(self, access_token, path=None):
@@ -85,7 +93,6 @@ class GithubOrganizationOAuth2(GithubMemberOAuth2):
username=user_data.get('login'))
-
class GithubTeamOAuth2(GithubMemberOAuth2):
"""Github OAuth2 authentication backend for teams"""
name = 'github-team'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git
More information about the Python-modules-commits
mailing list