omniauth 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of omniauth might be problematic. Click here for more details.
- data/.autotest +9 -0
- data/.document +5 -0
- data/.gitignore +36 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +4 -0
- data/Gemfile +6 -1
- data/README.markdown +121 -0
- data/Rakefile +50 -2
- data/lib/omniauth/version.rb +18 -4
- data/oa-basic/.gemtest +0 -0
- data/oa-basic/.rspec +3 -0
- data/oa-basic/.yardopts +4 -0
- data/oa-basic/LICENSE +19 -0
- data/oa-basic/README.rdoc +34 -0
- data/oa-basic/Rakefile +6 -0
- data/oa-basic/lib/oa-basic.rb +1 -0
- data/oa-basic/lib/omniauth/basic.rb +8 -0
- data/oa-basic/lib/omniauth/strategies/http_basic.rb +56 -0
- data/oa-basic/lib/omniauth/version.rb +19 -0
- data/oa-basic/oa-basic.gemspec +28 -0
- data/oa-basic/spec/omniauth/strategies/basic_spec.rb +7 -0
- data/oa-basic/spec/spec_helper.rb +11 -0
- data/oa-core/.gemtest +0 -0
- data/oa-core/.rspec +3 -0
- data/oa-core/.yardopts +4 -0
- data/oa-core/LICENSE +19 -0
- data/oa-core/Rakefile +6 -0
- data/oa-core/autotest/discover.rb +1 -0
- data/oa-core/lib/oa-core.rb +1 -0
- data/oa-core/lib/omniauth/builder.rb +33 -0
- data/oa-core/lib/omniauth/core.rb +135 -0
- data/oa-core/lib/omniauth/form.rb +184 -0
- data/oa-core/lib/omniauth/strategy.rb +227 -0
- data/oa-core/lib/omniauth/test.rb +12 -0
- data/oa-core/lib/omniauth/test/phony_session.rb +8 -0
- data/oa-core/lib/omniauth/test/strategy_macros.rb +34 -0
- data/oa-core/lib/omniauth/test/strategy_test_case.rb +49 -0
- data/oa-core/lib/omniauth/version.rb +19 -0
- data/oa-core/oa-core.gemspec +24 -0
- data/oa-core/spec/omniauth/builder_spec.rb +20 -0
- data/oa-core/spec/omniauth/core_spec.rb +79 -0
- data/oa-core/spec/omniauth/strategy_spec.rb +358 -0
- data/oa-core/spec/spec_helper.rb +12 -0
- data/oa-enterprise/.gemtest +0 -0
- data/oa-enterprise/.rspec +3 -0
- data/oa-enterprise/.yardopts +4 -0
- data/oa-enterprise/LICENSE +19 -0
- data/oa-enterprise/README.rdoc +82 -0
- data/oa-enterprise/Rakefile +6 -0
- data/oa-enterprise/lib/oa-enterprise.rb +1 -0
- data/oa-enterprise/lib/omniauth/enterprise.rb +8 -0
- data/oa-enterprise/lib/omniauth/strategies/cas.rb +47 -0
- data/oa-enterprise/lib/omniauth/strategies/cas/configuration.rb +98 -0
- data/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb +84 -0
- data/oa-enterprise/lib/omniauth/strategies/ldap.rb +111 -0
- data/oa-enterprise/lib/omniauth/strategies/ldap/adaptor.rb +279 -0
- data/oa-enterprise/lib/omniauth/version.rb +19 -0
- data/oa-enterprise/oa-enterprise.gemspec +32 -0
- data/oa-enterprise/spec/fixtures/cas_failure.xml +4 -0
- data/oa-enterprise/spec/fixtures/cas_success.xml +8 -0
- data/oa-enterprise/spec/omniauth/strategies/cas_spec.rb +94 -0
- data/oa-enterprise/spec/spec_helper.rb +14 -0
- data/oa-more/.gemtest +0 -0
- data/oa-more/.rspec +3 -0
- data/oa-more/.yardopts +4 -0
- data/oa-more/LICENSE +19 -0
- data/oa-more/README.rdoc +22 -0
- data/oa-more/Rakefile +6 -0
- data/oa-more/lib/oa-more.rb +1 -0
- data/oa-more/lib/omniauth/more.rb +9 -0
- data/oa-more/lib/omniauth/strategies/flickr.rb +86 -0
- data/oa-more/lib/omniauth/strategies/windows_live.rb +39 -0
- data/oa-more/lib/omniauth/strategies/windows_live/windowslivelogin.rb +1143 -0
- data/oa-more/lib/omniauth/strategies/yupoo.rb +67 -0
- data/oa-more/lib/omniauth/version.rb +19 -0
- data/oa-more/oa-more.gemspec +30 -0
- data/oa-more/spec/omniauth/strategies/flickr_spec.rb +7 -0
- data/oa-more/spec/spec_helper.rb +11 -0
- data/oa-oauth/.gemtest +0 -0
- data/oa-oauth/.rspec +3 -0
- data/oa-oauth/.yardopts +4 -0
- data/oa-oauth/LICENSE +19 -0
- data/oa-oauth/README.rdoc +35 -0
- data/oa-oauth/Rakefile +6 -0
- data/oa-oauth/autotest/discover.rb +1 -0
- data/oa-oauth/lib/oa-oauth.rb +1 -0
- data/oa-oauth/lib/omniauth/oauth.rb +53 -0
- data/oa-oauth/lib/omniauth/strategies/bitly.rb +46 -0
- data/oa-oauth/lib/omniauth/strategies/dailymile.rb +64 -0
- data/oa-oauth/lib/omniauth/strategies/doit.rb +60 -0
- data/oa-oauth/lib/omniauth/strategies/dopplr.rb +53 -0
- data/oa-oauth/lib/omniauth/strategies/douban.rb +60 -0
- data/oa-oauth/lib/omniauth/strategies/evernote.rb +54 -0
- data/oa-oauth/lib/omniauth/strategies/facebook.rb +70 -0
- data/oa-oauth/lib/omniauth/strategies/foursquare.rb +62 -0
- data/oa-oauth/lib/omniauth/strategies/github.rb +50 -0
- data/oa-oauth/lib/omniauth/strategies/goodreads.rb +44 -0
- data/oa-oauth/lib/omniauth/strategies/google.rb +80 -0
- data/oa-oauth/lib/omniauth/strategies/gowalla.rb +64 -0
- data/oa-oauth/lib/omniauth/strategies/hyves.rb +67 -0
- data/oa-oauth/lib/omniauth/strategies/identica.rb +49 -0
- data/oa-oauth/lib/omniauth/strategies/instagram.rb +56 -0
- data/oa-oauth/lib/omniauth/strategies/instapaper.rb +40 -0
- data/oa-oauth/lib/omniauth/strategies/linked_in.rb +55 -0
- data/oa-oauth/lib/omniauth/strategies/meetup.rb +56 -0
- data/oa-oauth/lib/omniauth/strategies/miso.rb +41 -0
- data/oa-oauth/lib/omniauth/strategies/mixi.rb +59 -0
- data/oa-oauth/lib/omniauth/strategies/netflix.rb +65 -0
- data/oa-oauth/lib/omniauth/strategies/oauth.rb +85 -0
- data/oa-oauth/lib/omniauth/strategies/oauth2.rb +98 -0
- data/oa-oauth/lib/omniauth/strategies/qzone.rb +69 -0
- data/oa-oauth/lib/omniauth/strategies/rdio.rb +45 -0
- data/oa-oauth/lib/omniauth/strategies/renren.rb +87 -0
- data/oa-oauth/lib/omniauth/strategies/salesforce.rb +44 -0
- data/oa-oauth/lib/omniauth/strategies/smug_mug.rb +42 -0
- data/oa-oauth/lib/omniauth/strategies/sound_cloud.rb +46 -0
- data/oa-oauth/lib/omniauth/strategies/t163.rb +57 -0
- data/oa-oauth/lib/omniauth/strategies/teambox.rb +49 -0
- data/oa-oauth/lib/omniauth/strategies/thirty_seven_signals.rb +41 -0
- data/oa-oauth/lib/omniauth/strategies/tqq.rb +64 -0
- data/oa-oauth/lib/omniauth/strategies/trade_me.rb +45 -0
- data/oa-oauth/lib/omniauth/strategies/trip_it.rb +22 -0
- data/oa-oauth/lib/omniauth/strategies/tsina.rb +79 -0
- data/oa-oauth/lib/omniauth/strategies/tsohu.rb +57 -0
- data/oa-oauth/lib/omniauth/strategies/tumblr.rb +60 -0
- data/oa-oauth/lib/omniauth/strategies/twitter.rb +57 -0
- data/oa-oauth/lib/omniauth/strategies/type_pad.rb +76 -0
- data/oa-oauth/lib/omniauth/strategies/vimeo.rb +54 -0
- data/oa-oauth/lib/omniauth/strategies/vkontakte.rb +84 -0
- data/oa-oauth/lib/omniauth/strategies/xauth.rb +67 -0
- data/oa-oauth/lib/omniauth/strategies/yahoo.rb +55 -0
- data/oa-oauth/lib/omniauth/strategies/yammer.rb +43 -0
- data/oa-oauth/lib/omniauth/strategies/you_tube.rb +73 -0
- data/oa-oauth/lib/omniauth/version.rb +19 -0
- data/oa-oauth/oa-oauth.gemspec +33 -0
- data/oa-oauth/spec/fixtures/basecamp_200.xml +24 -0
- data/oa-oauth/spec/fixtures/campfire_200.json +10 -0
- data/oa-oauth/spec/omniauth/strategies/bitly_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/dailymile_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/doit_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/dopplr_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/douban_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/evernote_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/facebook_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/foursquare_spec.rb +18 -0
- data/oa-oauth/spec/omniauth/strategies/github_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/goodreads_spec.rb +6 -0
- data/oa-oauth/spec/omniauth/strategies/google_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/gowalla_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/hyves_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/identica_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/linked_in_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/meetup_spec.rb +14 -0
- data/oa-oauth/spec/omniauth/strategies/miso_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/netflix_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/oauth2_spec.rb +0 -0
- data/oa-oauth/spec/omniauth/strategies/oauth_spec.rb +77 -0
- data/oa-oauth/spec/omniauth/strategies/rdio_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/salesforce_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/smug_mug_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/sound_cloud_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/t163_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/teambox_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/thirty_seven_signals_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/trade_me_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/trip_it_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/tsina_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/tumblr_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/twitter_spec.rb +20 -0
- data/oa-oauth/spec/omniauth/strategies/type_pad_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/vimeo_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/vkontakte_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/yahoo_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/yammer_spec.rb +5 -0
- data/oa-oauth/spec/omniauth/strategies/you_tube_spec.rb +5 -0
- data/oa-oauth/spec/spec_helper.rb +27 -0
- data/oa-oauth/spec/support/shared_examples.rb +29 -0
- data/oa-openid/.gemtest +0 -0
- data/oa-openid/.rspec +3 -0
- data/oa-openid/.yardopts +4 -0
- data/oa-openid/LICENSE +19 -0
- data/oa-openid/README.rdoc +51 -0
- data/oa-openid/Rakefile +6 -0
- data/oa-openid/lib/oa-openid.rb +1 -0
- data/oa-openid/lib/omniauth/openid.rb +59 -0
- data/oa-openid/lib/omniauth/openid/gapps.rb +32 -0
- data/oa-openid/lib/omniauth/strategies/google_apps.rb +23 -0
- data/oa-openid/lib/omniauth/strategies/open_id.rb +132 -0
- data/oa-openid/lib/omniauth/version.rb +19 -0
- data/oa-openid/oa-openid.gemspec +29 -0
- data/oa-openid/spec/omniauth/strategies/open_id_spec.rb +71 -0
- data/oa-openid/spec/spec_helper.rb +14 -0
- data/omniauth.gemspec +3 -3
- data/tasks/all.rb +134 -0
- metadata +199 -9
- data/README.rdoc +0 -17
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Netflix via OAuth and retrieve basic user information.
|
8
|
+
# Usage:
|
9
|
+
# use OmniAuth::Strategies::Netflix, 'consumerkey', 'consumersecret'
|
10
|
+
#
|
11
|
+
class Netflix < OmniAuth::Strategies::OAuth
|
12
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
13
|
+
opts = {
|
14
|
+
:site => 'http://api.netflix.com',
|
15
|
+
:request_token_path => "/oauth/request_token",
|
16
|
+
:access_token_path => "/oauth/access_token",
|
17
|
+
:authorize_url => "https://api-user.netflix.com/oauth/login"
|
18
|
+
}
|
19
|
+
super(app, :netflix, consumer_key, consumer_secret, opts, options, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def request_phase
|
23
|
+
request_token = consumer.get_request_token(:oauth_callback => callback_url)
|
24
|
+
session['oauth'] ||= {}
|
25
|
+
session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
26
|
+
r = Rack::Response.new
|
27
|
+
|
28
|
+
if request_token.callback_confirmed?
|
29
|
+
r.redirect(request_token.authorize_url(
|
30
|
+
:oauth_consumer_key => consumer.key
|
31
|
+
))
|
32
|
+
else
|
33
|
+
r.redirect(request_token.authorize_url(
|
34
|
+
:oauth_callback => callback_url,
|
35
|
+
:oauth_consumer_key => consumer.key
|
36
|
+
))
|
37
|
+
end
|
38
|
+
|
39
|
+
r.finish
|
40
|
+
end
|
41
|
+
|
42
|
+
def auth_hash
|
43
|
+
OmniAuth::Utils.deep_merge(super, {
|
44
|
+
'uid' => user_hash['user']['user_id'],
|
45
|
+
'user_info' => user_info,
|
46
|
+
'extra' => { 'user_hash' => user_hash['user'] }
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_info
|
51
|
+
user = user_hash['user']
|
52
|
+
{
|
53
|
+
'nickname' => user['nickname'],
|
54
|
+
'first_name' => user['first_name'],
|
55
|
+
'last_name' => user['last_name'],
|
56
|
+
'name' => "#{user['first_name']} #{user['last_name']}"
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def user_hash
|
61
|
+
@user_hash ||= MultiJson.decode(@access_token.get("http://api.netflix.com/users/#{@access_token.params[:user_id]}?output=json").body)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'oauth'
|
3
|
+
require 'omniauth/oauth'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class OAuth
|
8
|
+
include OmniAuth::Strategy
|
9
|
+
|
10
|
+
def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
|
11
|
+
self.consumer_key = consumer_key
|
12
|
+
self.consumer_secret = consumer_secret
|
13
|
+
self.consumer_options = consumer_options
|
14
|
+
super
|
15
|
+
self.options[:open_timeout] ||= 30
|
16
|
+
self.options[:read_timeout] ||= 30
|
17
|
+
self.options[:authorize_params] = options[:authorize_params] || {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def consumer
|
21
|
+
consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_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
|
+
attr_reader :name
|
28
|
+
attr_accessor :consumer_key, :consumer_secret, :consumer_options
|
29
|
+
|
30
|
+
def request_phase
|
31
|
+
request_token = consumer.get_request_token(:oauth_callback => callback_url)
|
32
|
+
session['oauth'] ||= {}
|
33
|
+
session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
34
|
+
r = Rack::Response.new
|
35
|
+
|
36
|
+
if request_token.callback_confirmed?
|
37
|
+
r.redirect(request_token.authorize_url(options[:authorize_params]))
|
38
|
+
else
|
39
|
+
r.redirect(request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url)))
|
40
|
+
end
|
41
|
+
|
42
|
+
r.finish
|
43
|
+
rescue ::Timeout::Error => e
|
44
|
+
fail!(:timeout, e)
|
45
|
+
end
|
46
|
+
|
47
|
+
def callback_phase
|
48
|
+
request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
|
49
|
+
|
50
|
+
opts = {}
|
51
|
+
if session['oauth'][name.to_s]['callback_confirmed']
|
52
|
+
opts[:oauth_verifier] = request['oauth_verifier']
|
53
|
+
else
|
54
|
+
opts[:oauth_callback] = callback_url
|
55
|
+
end
|
56
|
+
|
57
|
+
@access_token = request_token.get_access_token(opts)
|
58
|
+
super
|
59
|
+
rescue ::Timeout::Error => e
|
60
|
+
fail!(:timeout, e)
|
61
|
+
rescue ::Net::HTTPFatalError => e
|
62
|
+
fail!(:service_unavailable, e)
|
63
|
+
rescue ::OAuth::Unauthorized => e
|
64
|
+
fail!(:invalid_credentials, e)
|
65
|
+
rescue ::NoMethodError, ::MultiJson::DecodeError => e
|
66
|
+
fail!(:invalid_response, e)
|
67
|
+
end
|
68
|
+
|
69
|
+
def auth_hash
|
70
|
+
OmniAuth::Utils.deep_merge(super, {
|
71
|
+
'credentials' => {
|
72
|
+
'token' => @access_token.token,
|
73
|
+
'secret' => @access_token.secret
|
74
|
+
}, 'extra' => {
|
75
|
+
'access_token' => @access_token
|
76
|
+
}
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
80
|
+
def unique_id
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'uri'
|
3
|
+
require 'oauth2'
|
4
|
+
require 'omniauth/oauth'
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
# Authentication strategy for connecting with APIs constructed using
|
9
|
+
# the [OAuth 2.0 Specification](http://tools.ietf.org/html/draft-ietf-oauth-v2-10).
|
10
|
+
# You must generally register your application with the provider and
|
11
|
+
# utilize an application id and secret in order to authenticate using
|
12
|
+
# OAuth 2.0.
|
13
|
+
class OAuth2
|
14
|
+
include OmniAuth::Strategy
|
15
|
+
|
16
|
+
# The options passed in to the strategy.
|
17
|
+
attr_accessor :options
|
18
|
+
# The `OAuth2::Client` for this strategy.
|
19
|
+
attr_accessor :client_id, :client_secret, :client_options
|
20
|
+
|
21
|
+
# An error that is indicated in the OAuth 2.0 callback.
|
22
|
+
# This could be a `redirect_uri_mismatch` or other
|
23
|
+
class CallbackError < StandardError
|
24
|
+
attr_accessor :error, :error_reason, :error_uri
|
25
|
+
|
26
|
+
def initialize(error, error_reason=nil, error_uri=nil)
|
27
|
+
self.error = error
|
28
|
+
self.error_reason = error_reason
|
29
|
+
self.error_uri = error_uri
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Initialize a new OAuth 2.0 authentication provider.
|
34
|
+
|
35
|
+
# @param [Rack Application] app standard middleware application argument
|
36
|
+
# @param [String] name the name for this provider to be used in its URL, e.g. `/auth/name`
|
37
|
+
# @param [String] client_id the client/application ID of this provider
|
38
|
+
# @param [String] client_secret the client/application secret of this provider
|
39
|
+
# @param [Hash] options that will be passed through to the OAuth2::Client (see [oauth2 docs](http://rubydoc.info/gems/oauth2))
|
40
|
+
def initialize(app, name, client_id = nil, client_secret = nil, client_options = {}, options = {}, &block)
|
41
|
+
self.client_id = client_id
|
42
|
+
self.client_secret = client_secret
|
43
|
+
self.client_options = client_options
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def client
|
48
|
+
::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
|
49
|
+
end
|
50
|
+
|
51
|
+
def callback_url
|
52
|
+
full_host + callback_path
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
def request_phase
|
58
|
+
redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
|
59
|
+
end
|
60
|
+
|
61
|
+
def callback_phase
|
62
|
+
if request.params['error'] || request.params['error_reason']
|
63
|
+
raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
|
64
|
+
end
|
65
|
+
|
66
|
+
@access_token = build_access_token
|
67
|
+
|
68
|
+
if @access_token.expires? && @access_token.expires_in <= 0
|
69
|
+
client.request(:post, client.access_token_url, {
|
70
|
+
'client_id' => client_id,
|
71
|
+
'grant_type' => 'refresh_token',
|
72
|
+
'client_secret' => client_secret,
|
73
|
+
'refresh_token' => @access_token.refresh_token
|
74
|
+
}.merge(options))
|
75
|
+
@access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
|
76
|
+
end
|
77
|
+
|
78
|
+
super
|
79
|
+
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
|
80
|
+
fail!(:invalid_credentials, e)
|
81
|
+
rescue ::MultiJson::DecodeError => e
|
82
|
+
fail!(:invalid_response, e)
|
83
|
+
end
|
84
|
+
|
85
|
+
def build_access_token
|
86
|
+
verifier = request.params['code']
|
87
|
+
client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
|
88
|
+
end
|
89
|
+
|
90
|
+
def auth_hash
|
91
|
+
credentials = {'token' => @access_token.token}
|
92
|
+
credentials.merge('refresh_token' => @access_token.refresh_token) if @access_token.expires?
|
93
|
+
|
94
|
+
OmniAuth::Utils.deep_merge(super, {'credentials' => credentials})
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to qzone (QQ) via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Qzone, 'consumerkey', 'consumersecret'
|
13
|
+
#
|
14
|
+
class Qzone < OmniAuth::Strategies::OAuth
|
15
|
+
# Initialize the middleware
|
16
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
17
|
+
client_options = {
|
18
|
+
:site => 'http://openapi.qzone.qq.com',
|
19
|
+
:request_token_path => '/oauth/qzoneoauth_request_token',
|
20
|
+
:access_token_path => '/oauth/qzoneoauth_access_token',
|
21
|
+
:authorize_path => '/oauth/qzoneoauth_authorize',
|
22
|
+
:scheme => :query_string,
|
23
|
+
:http_method => :get
|
24
|
+
}
|
25
|
+
|
26
|
+
options[:authorize_params] = {:oauth_consumer_key => consumer_key}
|
27
|
+
super(app, :qzone, consumer_key, consumer_secret, client_options, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
#HACK qzone is using a none-standard parameter oauth_overicode
|
31
|
+
def consumer_options
|
32
|
+
@consumer_options[:access_token_path] = '/oauth/qzoneoauth_access_token?oauth_vericode=' + request['oauth_vericode'] if request['oauth_vericode']
|
33
|
+
@consumer_options
|
34
|
+
end
|
35
|
+
|
36
|
+
def callback_phase
|
37
|
+
session['oauth'][name.to_s]['callback_confirmed'] = true
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def auth_hash
|
42
|
+
ui = user_info
|
43
|
+
OmniAuth::Utils.deep_merge(super, {
|
44
|
+
'uid' => ui['uid'],
|
45
|
+
'user_info' => ui,
|
46
|
+
'extra' => {'user_hash' => user_hash}
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_info
|
51
|
+
user_hash = self.user_hash
|
52
|
+
{
|
53
|
+
'uid' => @access_token.params[:openid],
|
54
|
+
'nickname' => user_hash['nickname'],
|
55
|
+
'name' => user_hash['nickname'],
|
56
|
+
'image' => user_hash['figureurl'],
|
57
|
+
'urls' => {
|
58
|
+
'figureurl_1' => user_hash['figureurl_1'],
|
59
|
+
'figureurl_2' => user_hash['figureurl_2'],
|
60
|
+
}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def user_hash
|
65
|
+
@user_hash ||= MultiJson.decode(@access_token.get("/user/get_user_info?format=json&openid=#{@access_token.params[:openid]}").body)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Rdio via OAuth and retrieve basic user information.
|
8
|
+
# Usage:
|
9
|
+
# use OmniAuth::Strategies::Rdio, 'consumerkey', 'consumersecret'
|
10
|
+
#
|
11
|
+
class Rdio < OmniAuth::Strategies::OAuth
|
12
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
13
|
+
opts = {
|
14
|
+
:site => 'http://api.rdio.com',
|
15
|
+
:request_token_path => "/oauth/request_token",
|
16
|
+
:access_token_path => "/oauth/access_token",
|
17
|
+
:authorize_url => "https://www.rdio.com/oauth/authorize"
|
18
|
+
}
|
19
|
+
super(app, :rdio, consumer_key, consumer_secret, opts, options, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def auth_hash
|
23
|
+
OmniAuth::Utils.deep_merge(super, {
|
24
|
+
'uid' => user_hash['key'],
|
25
|
+
'user_info' => user_info,
|
26
|
+
'extra' => { 'user_hash' => user_hash }
|
27
|
+
})
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_info
|
31
|
+
user = user_hash
|
32
|
+
{
|
33
|
+
'nickname' => user['username'],
|
34
|
+
'first_name' => user['firstName'],
|
35
|
+
'last_name' => user['lastName'],
|
36
|
+
'name' => "#{user['firstName']} #{user['lastName']}"
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def user_hash
|
41
|
+
@user_hash ||= MultiJson.decode(@access_token.post("http://api.rdio.com/1/", { :method => 'currentUser', :extras => 'username' }).body)['result']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
# Authenticate to Renren utilizing OAuth 2.0 and retrieve
|
9
|
+
# basic user information.
|
10
|
+
#
|
11
|
+
# @example Basic Usage
|
12
|
+
# use OmniAuth::Strategies::Renren, 'client_id', 'client_secret'
|
13
|
+
class Renren < OAuth2
|
14
|
+
# @param [Rack Application] app standard middleware application parameter
|
15
|
+
# @param [String] client_id the application id as [registered on Renren](http://dev.renren.com/)
|
16
|
+
# @param [String] client_secret the application secret as registered on Renren
|
17
|
+
# @option options [String] :scope ('publish_feed,status_update') comma-separated extended permissions such as `publish_feed` and `status_update`
|
18
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
19
|
+
client_options = {
|
20
|
+
:site => "http://graph.renren.com/",
|
21
|
+
:authorize_url => "/oauth/authorize",
|
22
|
+
:access_token_url => "/oauth/token"
|
23
|
+
}
|
24
|
+
|
25
|
+
super(app, :renren, client_id, client_secret, client_options, options, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def user_data
|
29
|
+
@data ||= MultiJson.decode(Net::HTTP.post_form(URI.parse('http://api.renren.com/restserver.do'), signed_params).body)[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
def signed_params
|
33
|
+
params = {}
|
34
|
+
params[:api_key] = client.id
|
35
|
+
params[:method] = "users.getInfo"
|
36
|
+
params[:call_id] = Time.now.to_i
|
37
|
+
params[:format] = "json"
|
38
|
+
params[:v] = "1.0"
|
39
|
+
params[:uids] = session_key["user"]["id"]
|
40
|
+
params[:session_key] = session_key["renren_token"]["session_key"]
|
41
|
+
params[:sig] = Digest::MD5.hexdigest(params.map {|k,v| "#{k}=#{v}"}.sort.join("") + client.secret)
|
42
|
+
params
|
43
|
+
end
|
44
|
+
|
45
|
+
def session_key
|
46
|
+
@session_key ||= MultiJson.decode(@access_token.get('/renren_api/session_key'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_phase
|
50
|
+
options[:scope] ||= "publish_feed"
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_access_token
|
55
|
+
if renren_session.nil? || renrensession.empty?
|
56
|
+
super
|
57
|
+
else
|
58
|
+
@access_token = ::OAuth2::AccessToken.new(client, renren_session['access_token'])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def renren_session
|
63
|
+
session_cookie = request.cookies["rrs_#{client.id}"]
|
64
|
+
if session_cookie
|
65
|
+
@renren_session ||= Rack::Utils.parse_query(request.cookies["rrs_#{client.id}"].gsub('"', ''))
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def user_info
|
72
|
+
{
|
73
|
+
'name' => user_data["name"],
|
74
|
+
'image' => user_data["tinyurl"]
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def auth_hash
|
79
|
+
OmniAuth::Utils.deep_merge(super, {
|
80
|
+
'uid' => user_data['uid'],
|
81
|
+
'user_info' => user_info,
|
82
|
+
'extra' => {'user_hash' => user_data}
|
83
|
+
})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|