omniauth-taobao-oauth2 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/lib/omniauth/strategies/taobao.rb +73 -0
- data/lib/omniauth-taobao-oauth2/version.rb +6 -0
- data/lib/omniauth-taobao-oauth2.rb +3 -0
- data/omniauth-taobao-oauth2.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54740247e9ad828003d80b01009909413d39e315
|
4
|
+
data.tar.gz: a03dfdf3093afccab080ec42966efa577489d255
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f246cc13dd2a95bcfc1709431cf7ee9c2a95d76c9420acc043f642705e067d7e3a0b51b3b7368b012cfc383296f169a7622042cbfdbadd0f6d1683dd6459c3a
|
7
|
+
data.tar.gz: 78c06dc6b8e0630d99722c1d064a96e0ed7874a23c8d94aa7aee16b6a705be9fa27da081ca6447ac36388331e6555a472cd1e8a344cd42b23a0bc91e276bac08
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Howl王
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# OmniAuth Taobao OAuth2
|
2
|
+
|
3
|
+
Taobao OAuth2 Strategy for OmniAuth 1.0.
|
4
|
+
|
5
|
+
Read Taobao OAuth2 docs for more details: http://open.taobao.com/doc/detail.htm?spm=a219a.7386781.0.0.i9rfFM&id=118
|
6
|
+
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
Add to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-taobao-oauth2'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then `bundle install`.
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-taobao-oauth2
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
`OmniAuth::Strategies::Taobao` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
|
24
|
+
|
25
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
29
|
+
provider :taobao, ENV['TAOBAO_KEY'], ENV['TAOBAO_SECRET']
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Authentication Hash
|
34
|
+
|
35
|
+
Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
{
|
39
|
+
"provider" => "taobao",
|
40
|
+
"uid" => xxxxx,
|
41
|
+
"info" => {
|
42
|
+
"nickname" => "xxxxxxx"
|
43
|
+
},
|
44
|
+
"credentials" => {
|
45
|
+
"token" => "xxxxxxxxxxxxxxxxxxxxxx",
|
46
|
+
"refresh_token" => "xxxxxxxxxxxxxxxxxxxxxx",
|
47
|
+
"expires_at" => xxxxxx,
|
48
|
+
"expires" => true
|
49
|
+
},
|
50
|
+
"extra" => {
|
51
|
+
"raw_info" => {
|
52
|
+
"nick" => "xxxxxxx",
|
53
|
+
"user_id" => xxxxxxx
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
```
|
58
|
+
*PS.* Built and tested on MRI Ruby 1.9.3
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'omniauth-oauth2'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Taobao < OmniAuth::Strategies::OAuth2
|
7
|
+
option :name, 'taobao'
|
8
|
+
option :client_options, {
|
9
|
+
site: "https://oauth.taobao.com", #
|
10
|
+
authorize_url: "/authorize",
|
11
|
+
token_url: "/token"
|
12
|
+
}
|
13
|
+
option :token_params, {
|
14
|
+
:parse => :json
|
15
|
+
}
|
16
|
+
|
17
|
+
uid do
|
18
|
+
raw_info['user_id']
|
19
|
+
end
|
20
|
+
|
21
|
+
info do
|
22
|
+
{
|
23
|
+
nickname: raw_info['nick']
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
extra do
|
28
|
+
{
|
29
|
+
raw_info: raw_info
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def raw_info
|
34
|
+
access_token.options[:mode] = :query
|
35
|
+
@raw_info ||= ::OAuth2::Response.new(conn.get("/router/rest", signed_params)).parsed['user_seller_get_response']['user'] rescue {}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def conn
|
41
|
+
@conn ||= Faraday.new(url: "http://gw.api.taobao.com") do |req|
|
42
|
+
req.response :logger
|
43
|
+
req.adapter :excon
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def params
|
48
|
+
{
|
49
|
+
app_key: client.id,
|
50
|
+
method: 'taobao.user.seller.get',
|
51
|
+
fields: 'user_id,nick',
|
52
|
+
format: 'json',
|
53
|
+
session: access_token.token,
|
54
|
+
v: '2.0',
|
55
|
+
timestamp: timestamp,
|
56
|
+
partner_id: 'top-apitools'
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def signed_params
|
61
|
+
rand = client.secret + params.sort.flatten.join
|
62
|
+
sign = Digest::MD5.hexdigest(rand).to_s.upcase
|
63
|
+
params.merge(sign: sign)# 數字簽名
|
64
|
+
end
|
65
|
+
|
66
|
+
def timestamp # 时间戳
|
67
|
+
Time.now.strftime('%Y-%m-%d %H:%M:%S')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
OmniAuth.config.add_camelization "taobao", "Taobao"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-taobao-oauth2/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-taobao-oauth2"
|
8
|
+
spec.version = Omniauth::TaobaoOauth2::VERSION
|
9
|
+
spec.authors = ["Howl王"]
|
10
|
+
spec.email = ["mimosa@shareday.com"]
|
11
|
+
spec.description = %q{OmniAuth Oauth2 strategy for taobao.com.}
|
12
|
+
spec.summary = %q{OmniAuth Oauth2 strategy for taobao.com.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "excon"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-taobao-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Howl王
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: OmniAuth Oauth2 strategy for taobao.com.
|
56
|
+
email:
|
57
|
+
- mimosa@shareday.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/omniauth-taobao-oauth2.rb
|
68
|
+
- lib/omniauth-taobao-oauth2/version.rb
|
69
|
+
- lib/omniauth/strategies/taobao.rb
|
70
|
+
- omniauth-taobao-oauth2.gemspec
|
71
|
+
homepage: ''
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.3.0
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: OmniAuth Oauth2 strategy for taobao.com.
|
95
|
+
test_files: []
|