omniauth-tudou-oauth2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-tudou-oauth2.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,68 @@
1
+ # OmniAuth TuDou OAuth2
2
+
3
+ TuDou OAuth2 Strategy for OmniAuth 1.0.
4
+
5
+ Read TuDou OAuth2 docs for more details: http://open.tudou.com/wiki/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/%E9%AA%8C%E8%AF%81%E6%8E%88%E6%9D%83
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-tudou-oauth2'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-tudou-oauth2
20
+
21
+ ## Usage
22
+
23
+ `OmniAuth::Strategies::TuDou` 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 :tudou, ENV['TUDOU_KEY'], ENV['TUDOU_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 => 'tudou',
40
+ :uid => '123',
41
+ :info => {
42
+ :nickname => 'kdgsliu',
43
+ :name => 'kdgsliu',
44
+ :location => '',
45
+ :image => 'http://u4.tdimg.com/u/U-04.gif',
46
+ :description => ''
47
+ },
48
+ :credentials => {
49
+ :token => '123', # 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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'omniauth-tudou-oauth2/version'
3
+ require 'omniauth/strategies/tudou'
@@ -0,0 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Omniauth
3
+ module TuDouOauth2
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
@@ -0,0 +1,75 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'omniauth-oauth2'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class TuDou < OmniAuth::Strategies::OAuth2
7
+ option :name, 'tudou'
8
+ option :client_options, {
9
+ site: "https://api.tudou.com",
10
+ authorize_url: "/oauth2/authorize",
11
+ token_url: "/oauth2/access_token"
12
+ }
13
+ option :token_params, {
14
+ :parse => :json
15
+ }
16
+
17
+ uid do
18
+ raw_info['userId']
19
+ end
20
+
21
+ info do
22
+ {
23
+ nickname: raw_info['nickName'],
24
+ name: raw_info['nickName'],
25
+ location: '',
26
+ image: raw_info['userPicUrl'],
27
+ description: '',
28
+ }
29
+ end
30
+
31
+ extra do
32
+ {
33
+ raw_info: raw_info
34
+ }
35
+ end
36
+
37
+ def raw_info
38
+ access_token.options[:mode] = :query
39
+ access_token.options[:param_name] = 'access_token'
40
+ @uid ||= access_token.post('/oauth2/get_token_info', :parse => :json).parsed['uid']
41
+ @raw_info ||= access_token.get('/v6/user/info', params: signed_params(@uid), :parse => :json).parsed
42
+ end
43
+
44
+ ##
45
+ # You can pass +display+, +with_offical_account+ or +state+ params to the auth request, if
46
+ # you need to set them dynamically. You can also set these options
47
+ # in the OmniAuth config :authorize_params option.
48
+ #
49
+ def authorize_params
50
+ super.tap do |params|
51
+ %w[ state ].each do |v|
52
+ if request.params[v]
53
+ params[v.to_sym] = request.params[v]
54
+
55
+ # to support omniauth-oauth2's auto csrf protection
56
+ session['omniauth.state'] = params[:state] if v == 'state'
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def signed_params(uid)
65
+ {
66
+ format: 'json',
67
+ app_key: client.id,
68
+ user: uid
69
+ }
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ OmniAuth.config.add_camelization "tudou", "TuDou"
@@ -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-tudou-oauth2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-tudou-oauth2"
8
+ spec.version = Omniauth::TuDouOauth2::VERSION
9
+ spec.authors = ["Howl王"]
10
+ spec.email = ["mimosa@shareday.com"]
11
+ spec.description = %q{OmniAuth Oauth2 strategy for tudou.com.}
12
+ spec.summary = %q{OmniAuth Oauth2 strategy for tudou.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-tudou-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 tudou.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-tudou-oauth2.rb
59
+ - lib/omniauth-tudou-oauth2/version.rb
60
+ - lib/omniauth/strategies/tudou.rb
61
+ - omniauth-tudou-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 tudou.com.
87
+ test_files: []
88
+ has_rdoc: