omniauth-sina 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
6
+ *.swp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
6
+ - ree
7
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+ # Specify your gem's dependencies in omniauth-sina.gemspec
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # OmniAuth Sina
2
+
3
+ This gem contains the Sina strategy for OmniAuth.
4
+
5
+ The base strategie is fork from omniauth-oauth gem, and fix the problem at this patch that sina weibo does not return call_back_confirmed params when get request token.
6
+
7
+ ## How To Use It
8
+
9
+ Usage is as per any other OmniAuth 1.0 strategy. So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
10
+
11
+ gem 'omniauth-sina'
12
+
13
+ You can pull them in directly from github e.g.:
14
+
15
+ gem 'omniauth-sina', :git => 'https://github.com/mrichie/omniauth-sina'
16
+
17
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
18
+
19
+ Rails.application.config.middleware.use OmniAuth::Builder do
20
+ provider :sina, "consumer_key", "consumer_secret"
21
+ end
22
+
23
+ You will obviously have to put in your key and secret, which you get when you register your app with Sina Weibo[api.t.sina.com.cn] (they call them API Key and Secret Key).
24
+
25
+ Now just follow the README at: https://github.com/intridea/omniauth
26
+
27
+ ## Note on Patches/Pull Requests
28
+
29
+ - Fork the project.
30
+ - Make your feature addition or bug fix.
31
+ - Add tests for it. This is important so I don’t break it in a future version unintentionally.
32
+ - Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
33
+ - Send me a pull request. Bonus points for topic branches.
34
+
35
+ ## License
36
+
37
+ Copyright (c) 2011 by Richie Min
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new
9
+
10
+ desc 'Run specs'
11
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ require "omniauth-sina/version"
2
+ require 'omniauth/strategies/auth'
3
+ require 'omniauth/strategies/sina'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Sina
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,81 @@
1
+ require 'multi_json'
2
+ require 'oauth'
3
+ require 'omniauth'
4
+ module OmniAuth
5
+ module Strategies
6
+ class Auth
7
+ include OmniAuth::Strategy
8
+
9
+ args [:consumer_key, :consumer_secret]
10
+ option :consumer_key, nil
11
+ option :consumer_secret, nil
12
+ option :client_options, {}
13
+ option :open_timeout, 30
14
+ option :read_timeout, 30
15
+ option :callback_confirmed, nil
16
+ option :authorize_params, {}
17
+
18
+ attr_reader :access_token
19
+
20
+ def consumer
21
+ consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
22
+ consumer.http.open_timeout = options.open_timeout if options.open_timeout
23
+ consumer.http.read_timeout = options.read_timeout if options.read_timeout
24
+ consumer
25
+ end
26
+
27
+ def request_phase
28
+ request_token = consumer.get_request_token(:oauth_callback => callback_url)
29
+ session['oauth'] ||= {}
30
+ session['oauth'][name.to_s] = {'callback_confirmed' => options[:callback_confirmed] || request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
31
+
32
+ if request_token.callback_confirmed?
33
+ redirect request_token.authorize_url(options[:authorize_params])
34
+ else
35
+ redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
36
+ end
37
+
38
+ rescue ::Timeout::Error => e
39
+ fail!(:timeout, e)
40
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
41
+ fail!(:service_unavailable, e)
42
+ end
43
+
44
+ def callback_phase
45
+ raise OmniAuth::NoSessionError.new("Session Expired") if session['oauth'].nil?
46
+
47
+ request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
48
+
49
+ opts = {}
50
+ if session['oauth'][name.to_s]['callback_confirmed']
51
+ opts[:oauth_verifier] = request['oauth_verifier']
52
+ else
53
+ opts[:oauth_callback] = callback_url
54
+ end
55
+
56
+ @access_token = request_token.get_access_token(opts)
57
+ super
58
+ rescue ::Timeout::Error => e
59
+ fail!(:timeout, e)
60
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
61
+ fail!(:service_unavailable, e)
62
+ rescue ::OAuth::Unauthorized => e
63
+ fail!(:invalid_credentials, e)
64
+ rescue ::MultiJson::DecodeError => e
65
+ fail!(:invalid_response, e)
66
+ rescue ::OmniAuth::NoSessionError => e
67
+ fail!(:session_expired, e)
68
+ end
69
+
70
+ credentials do
71
+ {'token' => access_token.token, 'secret' => access_token.secret}
72
+ end
73
+
74
+ extra do
75
+ {'access_token' => access_token}
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ OmniAuth.config.add_camelization 'auth', 'Auth'
@@ -0,0 +1,37 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class Sina < OmniAuth::Strategies::Auth
4
+ option :name, 'sina'
5
+ option :client_options, {
6
+ :authorize_path => '/oauth/authorize',
7
+ :site => 'http://api.t.sina.com.cn',
8
+ :request_token_path => '/oauth/request_token',
9
+ :access_token_path => '/oauth/access_token'
10
+ }
11
+
12
+ option :callback_confirmed, true
13
+
14
+ uid { access_token.params[:user_id] }
15
+
16
+ info do
17
+ {
18
+ :nickname => raw_info['screen_name'],
19
+ :name => raw_info['name'],
20
+ :location => raw_info['location'],
21
+ :image => raw_info['profile_image_url'],
22
+ :description => raw_info['description'],
23
+ :urls => {
24
+ 'Website' => raw_info['url'],
25
+ 'Sina' => 'http://weibo.com/' + raw_info['screen_name'],
26
+ }
27
+ }
28
+ end
29
+
30
+ def raw_info
31
+ @raw_info ||= MultiJson.decode(access_token.get('/account/verify_credentials.json').body)
32
+ rescue ::Errno::ETIMEDOUT
33
+ raise ::Timeout::Error
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-sina/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-sina"
7
+ s.version = Omniauth::Sina::VERSION
8
+ s.authors = ["Richie Min"]
9
+ s.email = ["minruiqi@gmail.com"]
10
+ s.homepage = "https://github.com/mrichie/omniauth-sina"
11
+ s.summary = %q{OmniAuth strategy for Sina}
12
+ s.description = %q{OmniAuth strategy for Sina}
13
+
14
+ s.rubyforge_project = "omniauth-sina"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'rspec', '~> 2.7'
22
+ s.add_development_dependency 'rack-test'
23
+ s.add_development_dependency 'simplecov'
24
+ s.add_development_dependency 'webmock'
25
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Sina do
4
+ it 'should do some testing' do
5
+ pending
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-sina'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-sina
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Richie Min
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-01 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 2
32
+ - 7
33
+ version: "2.7"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rack-test
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: simplecov
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: webmock
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ description: OmniAuth strategy for Sina
79
+ email:
80
+ - minruiqi@gmail.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files: []
86
+
87
+ files:
88
+ - .gitignore
89
+ - .rspec
90
+ - .travis.yml
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - lib/omniauth-sina.rb
95
+ - lib/omniauth-sina/version.rb
96
+ - lib/omniauth/strategies/auth.rb
97
+ - lib/omniauth/strategies/sina.rb
98
+ - omniauth-sina.gemspec
99
+ - spec/omniauth/strategies/sina_spec.rb
100
+ - spec/spec_helper.rb
101
+ has_rdoc: true
102
+ homepage: https://github.com/mrichie/omniauth-sina
103
+ licenses: []
104
+
105
+ post_install_message:
106
+ rdoc_options: []
107
+
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ requirements: []
129
+
130
+ rubyforge_project: omniauth-sina
131
+ rubygems_version: 1.3.7
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: OmniAuth strategy for Sina
135
+ test_files: []
136
+