omniauth 0.2.6 → 0.3.0.rc3
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/README.md +62 -34
- data/lib/omniauth/version.rb +3 -3
- metadata +74 -228
- data/Gemfile +0 -12
- data/Rakefile +0 -51
- data/oa-basic/Gemfile +0 -7
- data/oa-basic/LICENSE +0 -19
- data/oa-basic/README.rdoc +0 -34
- data/oa-basic/Rakefile +0 -6
- data/oa-basic/lib/oa-basic.rb +0 -1
- data/oa-basic/lib/omniauth/basic.rb +0 -8
- data/oa-basic/lib/omniauth/strategies/http_basic.rb +0 -56
- data/oa-basic/lib/omniauth/version.rb +0 -19
- data/oa-basic/oa-basic.gemspec +0 -27
- data/oa-basic/spec/omniauth/strategies/basic_spec.rb +0 -7
- data/oa-basic/spec/spec_helper.rb +0 -11
- data/oa-core/Gemfile +0 -3
- data/oa-core/LICENSE +0 -19
- data/oa-core/Rakefile +0 -6
- data/oa-core/autotest/discover.rb +0 -1
- data/oa-core/lib/oa-core.rb +0 -1
- data/oa-core/lib/omniauth/builder.rb +0 -33
- data/oa-core/lib/omniauth/core.rb +0 -135
- data/oa-core/lib/omniauth/form.rb +0 -186
- data/oa-core/lib/omniauth/strategy.rb +0 -227
- data/oa-core/lib/omniauth/test.rb +0 -12
- data/oa-core/lib/omniauth/test/phony_session.rb +0 -8
- data/oa-core/lib/omniauth/test/strategy_macros.rb +0 -34
- data/oa-core/lib/omniauth/test/strategy_test_case.rb +0 -49
- data/oa-core/lib/omniauth/version.rb +0 -19
- data/oa-core/oa-core.gemspec +0 -24
- data/oa-core/spec/omniauth/builder_spec.rb +0 -20
- data/oa-core/spec/omniauth/core_spec.rb +0 -79
- data/oa-core/spec/omniauth/strategy_spec.rb +0 -363
- data/oa-core/spec/spec_helper.rb +0 -12
- data/oa-enterprise/Gemfile +0 -7
- data/oa-enterprise/LICENSE +0 -19
- data/oa-enterprise/README.rdoc +0 -82
- data/oa-enterprise/Rakefile +0 -6
- data/oa-enterprise/lib/oa-enterprise.rb +0 -1
- data/oa-enterprise/lib/omniauth/enterprise.rb +0 -8
- data/oa-enterprise/lib/omniauth/strategies/cas.rb +0 -47
- data/oa-enterprise/lib/omniauth/strategies/cas/configuration.rb +0 -98
- data/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb +0 -91
- data/oa-enterprise/lib/omniauth/strategies/ldap.rb +0 -111
- data/oa-enterprise/lib/omniauth/strategies/ldap/adaptor.rb +0 -279
- data/oa-enterprise/lib/omniauth/version.rb +0 -19
- data/oa-enterprise/oa-enterprise.gemspec +0 -31
- data/oa-enterprise/spec/fixtures/cas_failure.xml +0 -4
- data/oa-enterprise/spec/fixtures/cas_success.xml +0 -8
- data/oa-enterprise/spec/omniauth/strategies/cas_spec.rb +0 -94
- data/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb +0 -41
- data/oa-enterprise/spec/spec_helper.rb +0 -14
- data/oa-more/Gemfile +0 -7
- data/oa-more/LICENSE +0 -19
- data/oa-more/README.rdoc +0 -22
- data/oa-more/Rakefile +0 -6
- data/oa-more/lib/oa-more.rb +0 -1
- data/oa-more/lib/omniauth/more.rb +0 -11
- data/oa-more/lib/omniauth/strategies/draugiem.rb +0 -104
- data/oa-more/lib/omniauth/strategies/flickr.rb +0 -86
- data/oa-more/lib/omniauth/strategies/ign.rb +0 -93
- data/oa-more/lib/omniauth/strategies/windows_live.rb +0 -39
- data/oa-more/lib/omniauth/strategies/windows_live/windowslivelogin.rb +0 -1143
- data/oa-more/lib/omniauth/strategies/yupoo.rb +0 -67
- data/oa-more/lib/omniauth/version.rb +0 -19
- data/oa-more/oa-more.gemspec +0 -29
- data/oa-more/spec/omniauth/strategies/draugiem_spec.rb +0 -51
- data/oa-more/spec/omniauth/strategies/flickr_spec.rb +0 -7
- data/oa-more/spec/spec_helper.rb +0 -11
- data/oa-oauth/Gemfile +0 -7
- data/oa-oauth/LICENSE +0 -19
- data/oa-oauth/README.rdoc +0 -35
- data/oa-oauth/Rakefile +0 -6
- data/oa-oauth/autotest/discover.rb +0 -1
- data/oa-oauth/lib/oa-oauth.rb +0 -1
- data/oa-oauth/lib/omniauth/oauth.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/bitly.rb +0 -46
- data/oa-oauth/lib/omniauth/strategies/dailymile.rb +0 -64
- data/oa-oauth/lib/omniauth/strategies/doit.rb +0 -60
- data/oa-oauth/lib/omniauth/strategies/dopplr.rb +0 -53
- data/oa-oauth/lib/omniauth/strategies/douban.rb +0 -60
- data/oa-oauth/lib/omniauth/strategies/evernote.rb +0 -54
- data/oa-oauth/lib/omniauth/strategies/facebook.rb +0 -70
- data/oa-oauth/lib/omniauth/strategies/foursquare.rb +0 -62
- data/oa-oauth/lib/omniauth/strategies/github.rb +0 -50
- data/oa-oauth/lib/omniauth/strategies/goodreads.rb +0 -44
- data/oa-oauth/lib/omniauth/strategies/google.rb +0 -80
- data/oa-oauth/lib/omniauth/strategies/gowalla.rb +0 -72
- data/oa-oauth/lib/omniauth/strategies/hyves.rb +0 -67
- data/oa-oauth/lib/omniauth/strategies/identica.rb +0 -49
- data/oa-oauth/lib/omniauth/strategies/instagram.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/instapaper.rb +0 -40
- data/oa-oauth/lib/omniauth/strategies/linked_in.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/mailru.rb +0 -107
- data/oa-oauth/lib/omniauth/strategies/meetup.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/miso.rb +0 -41
- data/oa-oauth/lib/omniauth/strategies/mixi.rb +0 -59
- data/oa-oauth/lib/omniauth/strategies/netflix.rb +0 -65
- data/oa-oauth/lib/omniauth/strategies/oauth.rb +0 -83
- data/oa-oauth/lib/omniauth/strategies/oauth2.rb +0 -91
- data/oa-oauth/lib/omniauth/strategies/plurk.rb +0 -58
- data/oa-oauth/lib/omniauth/strategies/qzone.rb +0 -69
- data/oa-oauth/lib/omniauth/strategies/rdio.rb +0 -45
- data/oa-oauth/lib/omniauth/strategies/renren.rb +0 -87
- data/oa-oauth/lib/omniauth/strategies/salesforce.rb +0 -44
- data/oa-oauth/lib/omniauth/strategies/smug_mug.rb +0 -42
- data/oa-oauth/lib/omniauth/strategies/sound_cloud.rb +0 -46
- data/oa-oauth/lib/omniauth/strategies/t163.rb +0 -57
- data/oa-oauth/lib/omniauth/strategies/taobao.rb +0 -79
- data/oa-oauth/lib/omniauth/strategies/teambox.rb +0 -49
- data/oa-oauth/lib/omniauth/strategies/thirty_seven_signals.rb +0 -41
- data/oa-oauth/lib/omniauth/strategies/tqq.rb +0 -64
- data/oa-oauth/lib/omniauth/strategies/trade_me.rb +0 -45
- data/oa-oauth/lib/omniauth/strategies/trip_it.rb +0 -22
- data/oa-oauth/lib/omniauth/strategies/tsina.rb +0 -79
- data/oa-oauth/lib/omniauth/strategies/tsohu.rb +0 -57
- data/oa-oauth/lib/omniauth/strategies/tumblr.rb +0 -60
- data/oa-oauth/lib/omniauth/strategies/twitter.rb +0 -57
- data/oa-oauth/lib/omniauth/strategies/type_pad.rb +0 -76
- data/oa-oauth/lib/omniauth/strategies/vimeo.rb +0 -54
- data/oa-oauth/lib/omniauth/strategies/vkontakte.rb +0 -87
- data/oa-oauth/lib/omniauth/strategies/xauth.rb +0 -67
- data/oa-oauth/lib/omniauth/strategies/yahoo.rb +0 -55
- data/oa-oauth/lib/omniauth/strategies/yammer.rb +0 -43
- data/oa-oauth/lib/omniauth/strategies/you_tube.rb +0 -73
- data/oa-oauth/lib/omniauth/version.rb +0 -19
- data/oa-oauth/oa-oauth.gemspec +0 -32
- data/oa-oauth/spec/fixtures/basecamp_200.xml +0 -24
- data/oa-oauth/spec/fixtures/campfire_200.json +0 -10
- data/oa-oauth/spec/omniauth/strategies/bitly_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/dailymile_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/doit_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/dopplr_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/douban_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/evernote_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/facebook_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/foursquare_spec.rb +0 -18
- data/oa-oauth/spec/omniauth/strategies/github_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/goodreads_spec.rb +0 -6
- data/oa-oauth/spec/omniauth/strategies/google_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/gowalla_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/hyves_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/identica_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/linked_in_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/mailru_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/meetup_spec.rb +0 -14
- data/oa-oauth/spec/omniauth/strategies/miso_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/netflix_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/oauth2_spec.rb +0 -0
- data/oa-oauth/spec/omniauth/strategies/oauth_spec.rb +0 -77
- data/oa-oauth/spec/omniauth/strategies/plurk_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/rdio_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/salesforce_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/smug_mug_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/sound_cloud_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/t163_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/taobao_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/teambox_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/thirty_seven_signals_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/trade_me_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/trip_it_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/tsina_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/tumblr_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/twitter_spec.rb +0 -20
- data/oa-oauth/spec/omniauth/strategies/type_pad_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/vimeo_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/vkontakte_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/yahoo_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/yammer_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/you_tube_spec.rb +0 -5
- data/oa-oauth/spec/spec_helper.rb +0 -27
- data/oa-oauth/spec/support/shared_examples.rb +0 -29
- data/oa-openid/Gemfile +0 -7
- data/oa-openid/LICENSE +0 -19
- data/oa-openid/README.rdoc +0 -51
- data/oa-openid/Rakefile +0 -6
- data/oa-openid/lib/oa-openid.rb +0 -1
- data/oa-openid/lib/omniauth/openid.rb +0 -60
- data/oa-openid/lib/omniauth/openid/gapps.rb +0 -32
- data/oa-openid/lib/omniauth/strategies/google_apps.rb +0 -23
- data/oa-openid/lib/omniauth/strategies/open_id.rb +0 -132
- data/oa-openid/lib/omniauth/strategies/steam.rb +0 -55
- data/oa-openid/lib/omniauth/version.rb +0 -19
- data/oa-openid/oa-openid.gemspec +0 -28
- data/oa-openid/spec/omniauth/strategies/open_id_spec.rb +0 -71
- data/oa-openid/spec/spec_helper.rb +0 -14
- data/omniauth.gemspec +0 -20
- data/tasks/all.rb +0 -134
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'omniauth/oauth'
|
2
|
-
require 'multi_json'
|
3
|
-
|
4
|
-
module OmniAuth
|
5
|
-
module Strategies
|
6
|
-
#
|
7
|
-
# Authenticate with Meetup via OAuth and retrieve an access token for API usage
|
8
|
-
#
|
9
|
-
# Usage:
|
10
|
-
#
|
11
|
-
# use OmniAuth::Strategies::Meetup, 'consumerkey', 'consumersecret'
|
12
|
-
#
|
13
|
-
class Meetup < OmniAuth::Strategies::OAuth
|
14
|
-
# Initialize meetup middleware
|
15
|
-
# @param [Rack Application] app standard middleware application parameter
|
16
|
-
# @param [String] consumer_key the application consumer id
|
17
|
-
# @param [String] consumer_secret the application consumer secret
|
18
|
-
# @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
|
19
|
-
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
20
|
-
auth_path = (options[:sign_in] == false) ? 'http://www.meetup.com/authorize' : 'http://www.meetup.com/authenticate'
|
21
|
-
|
22
|
-
super(app, :meetup, consumer_key, consumer_secret,
|
23
|
-
{ :request_token_path => "https://api.meetup.com/oauth/request",
|
24
|
-
:access_token_path => "https://api.meetup.com/oauth/access",
|
25
|
-
:authorize_path => auth_path }, options)
|
26
|
-
end
|
27
|
-
|
28
|
-
def auth_hash
|
29
|
-
OmniAuth::Utils.deep_merge(super, {
|
30
|
-
'uid' => member['id'],
|
31
|
-
'user_info' => user_info,
|
32
|
-
'extra' => { 'user_hash' => member }
|
33
|
-
})
|
34
|
-
end
|
35
|
-
|
36
|
-
def user_info
|
37
|
-
{
|
38
|
-
'name' => member['name'],
|
39
|
-
'image' => member['photo_url'],
|
40
|
-
'location' => member['city'],
|
41
|
-
'urls' => {
|
42
|
-
'profile' => member['link']
|
43
|
-
}
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
def member
|
48
|
-
@member ||= parse(@access_token.get('https://api.meetup.com/members.json?relation=self').body)['results'][0]
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse(response)
|
52
|
-
MultiJson.decode(response)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'omniauth/oauth'
|
2
|
-
require 'multi_json'
|
3
|
-
|
4
|
-
module OmniAuth
|
5
|
-
module Strategies
|
6
|
-
#
|
7
|
-
# Authenticate to Miso via OAuth and retrieve basic
|
8
|
-
# user information.
|
9
|
-
#
|
10
|
-
# Usage:
|
11
|
-
#
|
12
|
-
# use OmniAuth::Strategies::Miso, 'consumerkey', 'consumersecret'
|
13
|
-
#
|
14
|
-
class Miso < OmniAuth::Strategies::OAuth
|
15
|
-
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
16
|
-
super(app, :miso, consumer_key, consumer_secret, {:site => 'https://gomiso.com'}, options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def auth_hash
|
20
|
-
OmniAuth::Utils.deep_merge(super, {
|
21
|
-
'uid' => user_hash['id'],
|
22
|
-
'user_info' => user_info,
|
23
|
-
'extra' => {'user_hash' => user_hash}
|
24
|
-
})
|
25
|
-
end
|
26
|
-
|
27
|
-
def user_info
|
28
|
-
{
|
29
|
-
'nickname' => user_hash['username'],
|
30
|
-
'name' => user_hash['full_name'],
|
31
|
-
'image' => user_hash['profile_image_url'],
|
32
|
-
'description' => user_hash['tagline'],
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
def user_hash
|
37
|
-
@user_hash ||= MultiJson.decode(@access_token.get('/api/oauth/v1/users/show.json').body)['user']
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'omniauth/oauth'
|
2
|
-
require 'multi_json'
|
3
|
-
|
4
|
-
module OmniAuth
|
5
|
-
module Strategies
|
6
|
-
# Authenticate to Facebook utilizing OAuth 2.0 and retrieve
|
7
|
-
# basic user information.
|
8
|
-
#
|
9
|
-
# @example Basic Usage
|
10
|
-
# use OmniAuth::Strategies::Mixi, 'client_id', 'client_secret'
|
11
|
-
class Mixi < OAuth2
|
12
|
-
# @option options [String] :scope separate the scopes by a space
|
13
|
-
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
14
|
-
client_options = {
|
15
|
-
:site => "https://mixi.jp/",
|
16
|
-
:authorize_url => "/connect_authorize.pl",
|
17
|
-
:access_token_url => "https://secure.mixi-platform.com/2/token"
|
18
|
-
}
|
19
|
-
|
20
|
-
super(app, :mixi, client_id, client_secret, client_options, options, &block)
|
21
|
-
end
|
22
|
-
|
23
|
-
def user_data
|
24
|
-
@data ||= MultiJson.decode(@access_token.get(
|
25
|
-
"http://api.mixi-platform.com/2/people/@me/@self",
|
26
|
-
{'oauth_token' => @access_token.token}
|
27
|
-
))
|
28
|
-
end
|
29
|
-
|
30
|
-
def request_phase
|
31
|
-
options[:scope] ||= "r_profile"
|
32
|
-
options[:display] ||= "pc"
|
33
|
-
options[:response_type] ||= 'code'
|
34
|
-
super
|
35
|
-
end
|
36
|
-
|
37
|
-
def callback_phase
|
38
|
-
options[:grant_type] ||= 'authorization_code'
|
39
|
-
super
|
40
|
-
end
|
41
|
-
|
42
|
-
def user_info
|
43
|
-
{
|
44
|
-
'nickname' => user_data['entry']['displayName'],
|
45
|
-
'image' => user_data['entry']['thumbnailUrl'],
|
46
|
-
'urls' => {:profile => user_data['entry']['profileUrl']}
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
def auth_hash
|
51
|
-
OmniAuth::Utils.deep_merge(super, {
|
52
|
-
'uid' => user_data['entry']['id'],
|
53
|
-
'user_info' => user_info,
|
54
|
-
'extra' => {'user_hash' => user_data['entry']}
|
55
|
-
})
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,65 +0,0 @@
|
|
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
|
@@ -1,83 +0,0 @@
|
|
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
|
-
|
35
|
-
if request_token.callback_confirmed?
|
36
|
-
redirect request_token.authorize_url(options[:authorize_params])
|
37
|
-
else
|
38
|
-
redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
|
39
|
-
end
|
40
|
-
|
41
|
-
rescue ::Timeout::Error => e
|
42
|
-
fail!(:timeout, e)
|
43
|
-
end
|
44
|
-
|
45
|
-
def callback_phase
|
46
|
-
request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
|
47
|
-
|
48
|
-
opts = {}
|
49
|
-
if session['oauth'][name.to_s]['callback_confirmed']
|
50
|
-
opts[:oauth_verifier] = request['oauth_verifier']
|
51
|
-
else
|
52
|
-
opts[:oauth_callback] = callback_url
|
53
|
-
end
|
54
|
-
|
55
|
-
@access_token = request_token.get_access_token(opts)
|
56
|
-
super
|
57
|
-
rescue ::Timeout::Error => e
|
58
|
-
fail!(:timeout, e)
|
59
|
-
rescue ::Net::HTTPFatalError => e
|
60
|
-
fail!(:service_unavailable, e)
|
61
|
-
rescue ::OAuth::Unauthorized => e
|
62
|
-
fail!(:invalid_credentials, e)
|
63
|
-
rescue ::NoMethodError, ::MultiJson::DecodeError => e
|
64
|
-
fail!(:invalid_response, e)
|
65
|
-
end
|
66
|
-
|
67
|
-
def auth_hash
|
68
|
-
OmniAuth::Utils.deep_merge(super, {
|
69
|
-
'credentials' => {
|
70
|
-
'token' => @access_token.token,
|
71
|
-
'secret' => @access_token.secret
|
72
|
-
}, 'extra' => {
|
73
|
-
'access_token' => @access_token
|
74
|
-
}
|
75
|
-
})
|
76
|
-
end
|
77
|
-
|
78
|
-
def unique_id
|
79
|
-
nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,91 +0,0 @@
|
|
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 + script_name + 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
|
-
@access_token = client.web_server.refresh_access_token(@access_token.refresh_token) if @access_token.expired?
|
68
|
-
|
69
|
-
super
|
70
|
-
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
|
71
|
-
fail!(:invalid_credentials, e)
|
72
|
-
rescue ::MultiJson::DecodeError => e
|
73
|
-
fail!(:invalid_response, e)
|
74
|
-
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
75
|
-
fail!(:timeout, e)
|
76
|
-
end
|
77
|
-
|
78
|
-
def build_access_token
|
79
|
-
verifier = request.params['code']
|
80
|
-
client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
|
81
|
-
end
|
82
|
-
|
83
|
-
def auth_hash
|
84
|
-
credentials = {'token' => @access_token.token}
|
85
|
-
credentials.merge!('refresh_token' => @access_token.refresh_token) if @access_token.expires?
|
86
|
-
|
87
|
-
OmniAuth::Utils.deep_merge(super, {'credentials' => credentials})
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'omniauth/oauth'
|
2
|
-
require 'multi_json'
|
3
|
-
|
4
|
-
module OmniAuth
|
5
|
-
module Strategies
|
6
|
-
#
|
7
|
-
# Authenticate to Plurk via OAuth and retrieve basic user info.
|
8
|
-
#
|
9
|
-
# Please note that this strategy relies on Plurk API 2.0,
|
10
|
-
# which is still in Beta.
|
11
|
-
#
|
12
|
-
# Usage:
|
13
|
-
# use OmniAuth::Strategies::Plurk
|
14
|
-
class Plurk < OmniAuth::Strategies::OAuth
|
15
|
-
|
16
|
-
# @param [Rack Application] app standard middleware application parameter
|
17
|
-
# @param [String] client_key App key [registered on plurk] (http://www.plurk.com/PlurkApp/register)
|
18
|
-
# @param [String] client_secret App secret registered on plurk
|
19
|
-
def initialize(app, client_key = nil, client_secret = nil, options = {}, &block)
|
20
|
-
client_options = { :site => 'http://www.plurk.com',
|
21
|
-
:request_token_path => '/OAuth/request_token',
|
22
|
-
:access_token_path => '/OAuth/access_token',
|
23
|
-
:authorize_path => '/OAuth/authorize' }
|
24
|
-
|
25
|
-
super(app, :plurk, client_key, client_secret, client_options, options)
|
26
|
-
end
|
27
|
-
|
28
|
-
def auth_hash
|
29
|
-
user = self.user_hash
|
30
|
-
OmniAuth::Utils.deep_merge(super, {
|
31
|
-
'uid' => user['id'],
|
32
|
-
'user_info' => user_info,
|
33
|
-
'extra' => {'user_hash' => user_hash}
|
34
|
-
})
|
35
|
-
end
|
36
|
-
|
37
|
-
def user_info
|
38
|
-
user = self.user_hash
|
39
|
-
{
|
40
|
-
'name' => user['full_name'],
|
41
|
-
'nickname' => user['display_name'] || user['nick_name'],
|
42
|
-
'location' => user['location'],
|
43
|
-
'image' => if user['has_profile_image'] == 1
|
44
|
-
"http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif"
|
45
|
-
else
|
46
|
-
"http://www.plurk.com/static/default_medium.gif"
|
47
|
-
end,
|
48
|
-
'urls' => { 'Plurk' => 'http://plurk.com/' + user['nick_name']}
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def user_hash
|
53
|
-
@user_hash ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info']
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|