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

use qq openid as username #763

Merged
merged 2 commits into from
Dec 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('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