Skip to content

Commit

Permalink
use openid as username
Browse files Browse the repository at this point in the history
  • Loading branch information
lneoe committed Oct 17, 2015
1 parent c7aba85 commit 53c24c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docs/backends/qq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/
20 changes: 19 additions & 1 deletion social/backends/qq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 53c24c8

Please sign in to comment.