omniauth-youku-oauth2 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +1 -0
- data/lib/omniauth-youku-oauth2.rb +3 -0
- data/lib/omniauth-youku-oauth2/version.rb +6 -0
- data/lib/omniauth/strategies/youku.rb +73 -0
- data/omniauth-youku-oauth2.gemspec +23 -0
- metadata +88 -0
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,68 @@
|
|
1
|
+
# OmniAuth Youku OAuth2
|
2
|
+
|
3
|
+
Youku OAuth2 Strategy for OmniAuth 1.0.
|
4
|
+
|
5
|
+
Read Youku OAuth2 docs for more details: http://open.youku.com/docs/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/api%E6%96%87%E6%A1%A3#oauth2授权_oauth2
|
6
|
+
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
Add to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-youku-oauth2'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then `bundle install`.
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-youku-oauth2
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
`OmniAuth::Strategies::Youku` 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 :youku, ENV['YOUKU_KEY'], ENV['YOUKU_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 => 'youku',
|
40
|
+
:uid => '87919223',
|
41
|
+
:info => {
|
42
|
+
:nickname => 'okingskyo',
|
43
|
+
:name => 'okingskyo',
|
44
|
+
:location => '',
|
45
|
+
:image => 'http://static.youku.com/v1.0.0742/user/img/head/150/999.jpg',
|
46
|
+
:description => '我勒个去'
|
47
|
+
},
|
48
|
+
:credentials => {
|
49
|
+
:token => '11d0b7627154f0dd000e6084f3811598', # OAuth 2.0 access_token, which you may wish to store
|
50
|
+
:expires_at => 3600, # when the access token expires (if it expires)
|
51
|
+
:expires => true # if you request `offline_access` this will be false
|
52
|
+
},
|
53
|
+
:extra => {
|
54
|
+
:raw_info => {
|
55
|
+
... # data from /users/myinfo.json, check by yourself
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
```
|
60
|
+
*PS.* Built and tested on MRI Ruby 1.9.3
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
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
|
+
require 'awesome_print'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class Youku < OmniAuth::Strategies::OAuth2
|
8
|
+
option :name, 'youku'
|
9
|
+
option :client_options, {
|
10
|
+
site: "https://openapi.youku.com", # 第二版
|
11
|
+
authorize_url: "/v2/oauth2/authorize",
|
12
|
+
token_url: "/v2/oauth2/token"
|
13
|
+
}
|
14
|
+
option :token_params, {
|
15
|
+
:parse => :json
|
16
|
+
}
|
17
|
+
|
18
|
+
uid do
|
19
|
+
raw_info['id']
|
20
|
+
end
|
21
|
+
|
22
|
+
info do
|
23
|
+
{
|
24
|
+
nickname: raw_info['name'],
|
25
|
+
name: raw_info['name'],
|
26
|
+
location: '',
|
27
|
+
image: raw_info['avatar_large'],
|
28
|
+
description: raw_info['description'],
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
extra do
|
33
|
+
{
|
34
|
+
raw_info: raw_info
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def raw_info
|
39
|
+
access_token.options[:mode] = :query
|
40
|
+
@raw_info ||= access_token.get('/v2/users/myinfo.json', params: signed_params).parsed
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# You can pass +display+, +with_offical_account+ or +state+ params to the auth request, if
|
45
|
+
# you need to set them dynamically. You can also set these options
|
46
|
+
# in the OmniAuth config :authorize_params option.
|
47
|
+
#
|
48
|
+
def authorize_params
|
49
|
+
super.tap do |params|
|
50
|
+
%w[ state ].each do |v|
|
51
|
+
if request.params[v]
|
52
|
+
params[v.to_sym] = request.params[v]
|
53
|
+
|
54
|
+
# to support omniauth-oauth2's auto csrf protection
|
55
|
+
session['omniauth.state'] = params[:state] if v == 'state'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def signed_params
|
64
|
+
{
|
65
|
+
client_id: client.id,
|
66
|
+
access_token: access_token.token
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
OmniAuth.config.add_camelization "youku", "Youku"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-youku-oauth2/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-youku-oauth2"
|
8
|
+
spec.version = Omniauth::YoukuOauth2::VERSION
|
9
|
+
spec.authors = ["Howl王"]
|
10
|
+
spec.email = ["mimosa@shareday.com"]
|
11
|
+
spec.description = %q{OmniAuth Oauth2 strategy for youku.com.}
|
12
|
+
spec.summary = %q{OmniAuth Oauth2 strategy for youku.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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-youku-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Howl王
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :development
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
|
+
description: OmniAuth Oauth2 strategy for youku.com.
|
47
|
+
email:
|
48
|
+
- mimosa@shareday.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/omniauth-youku-oauth2.rb
|
59
|
+
- lib/omniauth-youku-oauth2/version.rb
|
60
|
+
- lib/omniauth/strategies/youku.rb
|
61
|
+
- omniauth-youku-oauth2.gemspec
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
none: false
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
none: false
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: OmniAuth Oauth2 strategy for youku.com.
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|