Skip to content
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
4 changes: 3 additions & 1 deletion examples/django_example/example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
<a href="{% url 'social:begin' 'yahoo' %}">Yahoo OpenId</a> <br />
<a href="{% url 'social:begin' 'yahoo-oauth' %}">Yahoo OAuth1</a> <br />
<a href="{% url 'social:begin' 'yammer' %}">Yammer OAuth2</a> <br />
<a href="{% url 'social:begin' 'yandex-oauth2' %}">Yandex OAuth2</a> <br />
<a href="{% url 'social:begin' 'yandex-oauth2' %}">Yandex OAuth2</a>
<br />
<a href="{% url 'social:begin' 'taobao' %}">TAOBAO OAuth2</a> <br />

<a href="{% url 'social:begin' 'email' %}">Email Auth</a> <br />
<a href="{% url 'social:begin' 'username' %}">Username Auth</a> <br />
Expand Down
39 changes: 39 additions & 0 deletions social/backends/taobao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
from social.exceptions import AuthFailed
from social.backends.oauth import BaseOAuth2
# taobao OAuth base configuration
TAOBAO_OAUTH_HOST = 'oauth.taobao.com'
# TAOBAO_OAUTH_ROOT = 'authorize'
#Always use secure connection
TAOBAO_OAUTH_AUTHORIZATION_URL = 'https://%s/authorize' % (TAOBAO_OAUTH_HOST)
TAOBAO_OAUTH_ACCESS_TOKEN_URL = 'https://%s/token' % (TAOBAO_OAUTH_HOST)

TAOBAO_CHECK_AUTH = 'https://eco.taobao.com/router/rest'

class TAOBAOAuth(BaseOAuth2):
"""Taobao OAuth authentication mechanism"""
name="taobao"
ID_KEY='taobao_user_id'
AUTHORIZATION_URL = TAOBAO_OAUTH_AUTHORIZATION_URL
ACCESS_TOKEN_URL = TAOBAO_OAUTH_ACCESS_TOKEN_URL

def user_data(self, access_token, *args, **kwargs):
"""Return user data provided"""
params = {'method':'taobao.user.get',
'fomate':'json',
'v':'2.0',
'access_token': access_token}
try:
return self.get_json(TAOBAO_CHECK_AUTH, params=params)
except ValueError:
return None

def get_user_details(self, response):
"""Return user details from Taobao account"""
username = response.get('taobao_user_nick')
return {'username': username}

# Backend definition
BACKENDS = {
'taobao': TAOBAOAuth,
}
37 changes: 37 additions & 0 deletions social/tests/backends/test_taobao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json

from social.tests.backends.oauth import OAuth2Test

TAOBAO_OAUTH_HOST = 'oauth.taobao.com'
# TAOBAO_OAUTH_ROOT = 'authorize'
#Always use secure connection
TAOBAO_OAUTH_REQUEST_TOKEN_URL = 'https://%s/request_token' % (TAOBAO_OAUTH_HOST)
TAOBAO_OAUTH_AUTHORIZATION_URL = 'https://%s/authorize' % (TAOBAO_OAUTH_HOST)
TAOBAO_OAUTH_ACCESS_TOKEN_URL = 'https://%s/token' % (TAOBAO_OAUTH_HOST)

TAOBAO_CHECK_AUTH = 'https://eco.taobao.com/router/rest'
TAOBAO_USER_SHOW = 'https://%s/user/get_user_info' % TAOBAO_OAUTH_HOST
class TaobaoOAuth2Test(OAuth2Test):
backend_path = 'social.backends.taobao.TAOBAOAuth'
user_data_url = TAOBAO_CHECK_AUTH
expected_username = 'foobar'
access_token_body = json.dumps({
'access_token': 'foobar',
'token_type': 'bearer'
})
user_data_body = json.dumps( {
"w2_expires_in": 0,
"taobao_user_id": "1",
"taobao_user_nick": "foobar",
"w1_expires_in": 1800,
"re_expires_in": 0,
"r2_expires_in": 0,
"expires_in": 86400,
"r1_expires_in": 1800
})

def test_login(self):
self.do_login()

def test_partial_pipeline(self):
self.do_partial_pipeline()