[Python-modules-commits] [python-social-auth] 42/71: use `openid` as username

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:14:27 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.14
in repository python-social-auth.

commit 53c24c846aee5bbbfe5969d727441fd9b0d53fe3
Author: lneoe <joe.hu.c+git at gmail.com>
Date:   Wed Oct 14 16:02:36 2015 +0800

    use `openid` as username
---
 docs/backends/qq.rst  |  6 +++++-
 social/backends/qq.py | 20 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/docs/backends/qq.rst b/docs/backends/qq.rst
index 2f3a932..97b7486 100644
--- a/docs/backends/qq.rst
+++ b/docs/backends/qq.rst
@@ -22,6 +22,10 @@ QQ implemented OAuth2 protocol for their authentication mechanism. To enable
 
 The values for ``nickname``, ``figureurl_qq_1`` and ``gender`` will be stored
 in the ``extra_data`` field. The ``nickname`` will be used as the account
-username. ``figureurl_qq_1`` can be used as the profile image.
+username. ``figureurl_qq_1`` can be used as the profile image. sometimes
+nickname will duplicate with another qq account, to avoid this issue it's
+possible to use ``openid`` as ``username`` by define this setting::
+
+    SOCIAL_AUTH_QQ_USE_OPENID_AS_USERNAME = True
 
 .. _QQ: http://connect.qq.com/
diff --git a/social/backends/qq.py b/social/backends/qq.py
index 0a50df7..4894b60 100644
--- a/social/backends/qq.py
+++ b/social/backends/qq.py
@@ -25,8 +25,26 @@ class QQOAuth2(BaseOAuth2):
     ]
 
     def get_user_details(self, response):
+        """
+        Return user detail from QQ account
+        sometimes nickname will duplicate with another qq account, to avoid
+        this issue it's possible to use `openid` as `username` by define
+        `SOCIAL_AUTH_QQ_USE_OPENID_AS_USERNAME = True`
+        """
+        if self.setting('SOCIAL_AUTH_QQ_USE_OPENID_AS_USERNAME', False):
+            username = response.get('openid', '')
+        else:
+            username = response.get('nickname', '')
+
+        fullname, first_name, last_name = self.get_user_names(
+            first_name=response.get('nickname', '')
+        )
+
         return {
-            'username': response.get('nickname', '')
+            'username': username,
+            'fullname': fullname,
+            'first_name': first_name,
+            'last_name': last_name
         }
 
     def get_openid(self, access_token):

-- 
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