Skip to content

Commit

Permalink
Support Weibo domain as username by setting. Closes #164
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed Jan 18, 2014
1 parent 9f27a67 commit 61fae87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/backends/weibo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ Weibo OAuth 2.0 workflow.
By default ``account id``, ``profile_image_url`` and ``gender`` are stored in
extra_data field.

The user name is used by default to build the user instance ``username``,
sometimes this contains non-ASCII characters which might not be desirable for
the website. To avoid this issue it's possible to use the Weibo ``domain``
which will be inside the ASCII range by defining this setting::

SOCIAL_AUTH_WEIBO_DOMAIN_AS_USERNAME = True

.. _Weibo: http://open.weibo.com
6 changes: 5 additions & 1 deletion social/backends/weibo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def get_user_details(self, response):
"""Return user details from Weibo. API URL is:
https://api.weibo.com/2/users/show.json/?uid=<UID>&access_token=<TOKEN>
"""
return {'username': response.get("name", ""),
if self.setting('DOMAIN_AS_USERNAME'):
username = response.get('domain', '')
else:
username = response.get('name', '')
return {'username': username,
'first_name': response.get('screen_name', '')}

def user_data(self, access_token, *args, **kwargs):
Expand Down

0 comments on commit 61fae87

Please sign in to comment.