omniauth-taobao 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +72 -0
- data/Rakefile +1 -0
- data/lib/omniauth-taobao.rb +2 -0
- data/lib/omniauth-taobao/version.rb +5 -0
- data/lib/omniauth/strategies/taobao.rb +75 -0
- data/omniauth-taobao.gemspec +26 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
### How does omniauth-taobao work with Taobao
|
2
|
+
|
3
|
+
#### API permission levels
|
4
|
+
|
5
|
+
Taobao has three API permission levels
|
6
|
+
|
7
|
+
* Default API (Requires additional approval from Taobao)
|
8
|
+
* Buyer API
|
9
|
+
* Seller API
|
10
|
+
|
11
|
+
These permission levels are granted during your app application process based on your app type.
|
12
|
+
To configure omniauth-taobao work with the correct type, please use something like this (omniauth + device example in devise.rb file):
|
13
|
+
|
14
|
+
```
|
15
|
+
config.omniauth :taobao, "Your_APP_Key", "Your_APP_Secret", :strategy_class => OmniAuth::Strategies::Taobao, :client_options => {:user_type => :seller}
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
The ```:user_type``` option can be one of ```:default```,```:buyer``` and ```:seller```.
|
20
|
+
|
21
|
+
#### User Get Info Response
|
22
|
+
|
23
|
+
Different API Permission levels needs to use different API to obtain user's info.
|
24
|
+
|
25
|
+
The documentation for these API can be found [here](http://open.taobao.com/doc/api_cat_detail.htm?spm=0.0.0.0.JJ4lrk&cat_id=1&category_id=102)
|
26
|
+
|
27
|
+
omniauth-taobao will chose the proper API method based on your ```:user_type``` option.
|
28
|
+
|
29
|
+
#### Sample API Response (For Seller API)
|
30
|
+
|
31
|
+
```
|
32
|
+
--- !ruby/hash:OmniAuth::AuthHash
|
33
|
+
provider: taobao
|
34
|
+
uid:
|
35
|
+
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
|
36
|
+
uid:
|
37
|
+
nickname: UserNickName
|
38
|
+
email:
|
39
|
+
user_info: !ruby/hash:OmniAuth::AuthHash
|
40
|
+
alipay_bind: bind
|
41
|
+
consumer_protection: true/false
|
42
|
+
nick: UserNickName
|
43
|
+
seller_credit: !ruby/hash:OmniAuth::AuthHash
|
44
|
+
good_num: 7
|
45
|
+
level: 1
|
46
|
+
score: 7
|
47
|
+
total_num: 7
|
48
|
+
sex: m
|
49
|
+
status: normal
|
50
|
+
type: C
|
51
|
+
user_id: 1212121212
|
52
|
+
extra: !ruby/hash:OmniAuth::AuthHash
|
53
|
+
user_hash: !ruby/hash:OmniAuth::AuthHash
|
54
|
+
alipay_bind: bind
|
55
|
+
consumer_protection: true
|
56
|
+
nick: UserNickName
|
57
|
+
seller_credit: !ruby/hash:OmniAuth::AuthHash
|
58
|
+
good_num: 7
|
59
|
+
level: 1
|
60
|
+
score: 7
|
61
|
+
total_num: 7
|
62
|
+
sex: m
|
63
|
+
status: normal
|
64
|
+
type: C
|
65
|
+
user_id: 1212121212
|
66
|
+
credentials: !ruby/hash:OmniAuth::AuthHash
|
67
|
+
token: Token
|
68
|
+
refresh_token: refresh_token
|
69
|
+
expires_at: 13722222220
|
70
|
+
expires: true
|
71
|
+
extra: !ruby/hash:OmniAuth::AuthHash {}
|
72
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# lots of stuff taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth2/taobao.rb
|
2
|
+
require 'omniauth-oauth2'
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Taobao < OmniAuth::Strategies::OAuth2
|
6
|
+
USER_METHODS = {
|
7
|
+
:default => 'taobao.user.get',
|
8
|
+
:buyer => 'taobao.user.buyer.get',
|
9
|
+
:seller => 'taobao.user.seller.get'
|
10
|
+
}
|
11
|
+
|
12
|
+
USER_RESPONSE = {
|
13
|
+
:default => 'user_get_response',
|
14
|
+
:buyer => 'user_buyer_get_response',
|
15
|
+
:seller => 'user_seller_get_response'
|
16
|
+
}
|
17
|
+
|
18
|
+
option :client_options, {
|
19
|
+
:authorize_url => 'https://oauth.taobao.com/authorize',
|
20
|
+
:token_url => 'https://oauth.taobao.com/token',
|
21
|
+
}
|
22
|
+
def request_phase
|
23
|
+
options[:state] ||= '1'
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
uid { raw_info['uid'] }
|
28
|
+
|
29
|
+
info do
|
30
|
+
{
|
31
|
+
'uid' => raw_info['uid'],
|
32
|
+
'nickname' => raw_info['nick'],
|
33
|
+
'email' => raw_info['email'],
|
34
|
+
'user_info' => raw_info,
|
35
|
+
'extra' => {
|
36
|
+
'user_hash' => raw_info,
|
37
|
+
},
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def raw_info
|
42
|
+
url = 'http://gw.api.taobao.com/router/rest'
|
43
|
+
|
44
|
+
user_type = options.client_options.user_type || :default
|
45
|
+
query_param = {
|
46
|
+
:app_key => options.client_id,
|
47
|
+
|
48
|
+
# TODO to be moved in options
|
49
|
+
# TODO add more default fields (http://my.open.taobao.com/apidoc/index.htm#categoryId:1-dataStructId:3)
|
50
|
+
:fields => 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,created,last_visit,birthday,type,status,alipay_no,alipay_account,alipay_account,email,consumer_protection,alipay_bind',
|
51
|
+
:format => 'json',
|
52
|
+
:method => USER_METHODS[user_type],
|
53
|
+
:session => @access_token.token,
|
54
|
+
:sign_method => 'md5',
|
55
|
+
:timestamp => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
56
|
+
:v => '2.0'
|
57
|
+
}
|
58
|
+
query_param = generate_sign(query_param)
|
59
|
+
res = Net::HTTP.post_form(URI.parse(url), query_param)
|
60
|
+
response = MultiJson.decode(res.body)
|
61
|
+
raise OmniAuth::Error.new(response['error_response']) if response.has_key?('error_response')
|
62
|
+
@raw_info ||= response[USER_RESPONSE[user_type]]['user']
|
63
|
+
rescue ::Errno::ETIMEDOUT
|
64
|
+
raise ::Timeout::Error
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_sign(params)
|
68
|
+
# params.sort.collect { |k, v| "#{k}#{v}" }
|
69
|
+
str = options.client_secret + params.sort {|a,b| "#{a[0]}"<=>"#{b[0]}"}.flatten.join + options.client_secret
|
70
|
+
params['sign'] = Digest::MD5.hexdigest(str).upcase!
|
71
|
+
params
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-taobao/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-taobao"
|
7
|
+
s.version = Omniauth::Taobao::VERSION
|
8
|
+
s.authors = ["Scott Ballantyne"]
|
9
|
+
s.email = ["ussballantyne@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{an omniauth strategy for taobao}
|
12
|
+
s.description = %q{an omniauth strategy for taobao}
|
13
|
+
|
14
|
+
s.rubyforge_project = "omniauth-taobao"
|
15
|
+
s.add_dependency 'omniauth', '~> 1.1.4'
|
16
|
+
s.add_dependency 'omniauth-oauth2', '~> 1.1.1'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
# specify any dependencies here; for example:
|
24
|
+
# s.add_development_dependency "rspec"
|
25
|
+
# s.add_runtime_dependency "rest-client"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-taobao
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scott Ballantyne
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: omniauth-oauth2
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.1.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.1
|
46
|
+
description: an omniauth strategy for taobao
|
47
|
+
email:
|
48
|
+
- ussballantyne@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/omniauth-taobao.rb
|
58
|
+
- lib/omniauth-taobao/version.rb
|
59
|
+
- lib/omniauth/strategies/taobao.rb
|
60
|
+
- omniauth-taobao.gemspec
|
61
|
+
homepage: ''
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project: omniauth-taobao
|
81
|
+
rubygems_version: 1.8.25
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: an omniauth strategy for taobao
|
85
|
+
test_files: []
|