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,57 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Tsohu via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Tsohu, 'APIKey', 'APIKeySecret'
|
13
|
+
#
|
14
|
+
class Tsohu < OmniAuth::Strategies::OAuth
|
15
|
+
|
16
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
17
|
+
@api_key = consumer_key
|
18
|
+
|
19
|
+
client_options = {
|
20
|
+
:site => 'http://api.t.sohu.com',
|
21
|
+
:request_token_path => '/oauth/request_token',
|
22
|
+
:access_token_path => '/oauth/access_token',
|
23
|
+
:authorize_path => '/oauth/authorize',
|
24
|
+
:scheme => :header,
|
25
|
+
}
|
26
|
+
|
27
|
+
super(app, :tsohu, consumer_key, consumer_secret, client_options, options, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def auth_hash
|
31
|
+
OmniAuth::Utils.deep_merge(super, {
|
32
|
+
'uid' => user_hash['id'],
|
33
|
+
'user_info' => user_info,
|
34
|
+
'extra' => {'user_hash' => user_hash}
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_info
|
39
|
+
user_hash = self.user_hash
|
40
|
+
{
|
41
|
+
'username' => user_hash['screen_name'],
|
42
|
+
'name' => user_hash['name'],
|
43
|
+
'location' => user_hash['location'],
|
44
|
+
'image' => user_hash['profile_image_url'],
|
45
|
+
'description' => user_hash['description'],
|
46
|
+
'urls' => {
|
47
|
+
'Tsohu' => user_hash['url']
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_hash
|
53
|
+
@user_hash ||= MultiJson.decode(@access_token.get("http://api.t.sohu.com/account/verify_credentials.json").body)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
#
|
6
|
+
# Authenticate to Tumblr via OAuth and retrieve basic
|
7
|
+
# user information.
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
#
|
11
|
+
# use OmniAuth::Strategies::Tumblr, 'consumerkey', 'consumersecret'
|
12
|
+
#
|
13
|
+
class Tumblr < OmniAuth::Strategies::OAuth
|
14
|
+
# Initialize the middleware
|
15
|
+
#
|
16
|
+
# @option options [Boolean, true] :sign_in When true, use the "Sign in with Tumblr" flow instead of the authorization flow.
|
17
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
18
|
+
client_options = {
|
19
|
+
:site => 'http://www.tumblr.com'
|
20
|
+
}
|
21
|
+
|
22
|
+
client_options[:authorize_path] = '/oauth/authorize' unless options[:sign_in] == false
|
23
|
+
super(app, :tumblr, consumer_key, consumer_secret, client_options, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def auth_hash
|
27
|
+
OmniAuth::Utils.deep_merge(super, {
|
28
|
+
'uid' => user['name'],
|
29
|
+
'user_info' => user_info,
|
30
|
+
'extra' => { 'user_hash' => user }
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_info
|
35
|
+
{
|
36
|
+
'nickname' => user['name'],
|
37
|
+
'name' => user['title'],
|
38
|
+
'image' => user['avatar_url'],
|
39
|
+
'urls' => {
|
40
|
+
'website' => user['url'],
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def user
|
46
|
+
tumblelogs = user_hash['tumblr']['tumblelog']
|
47
|
+
if tumblelogs.kind_of?(Array)
|
48
|
+
@user ||= tumblelogs[0]
|
49
|
+
else
|
50
|
+
@user ||= tumblelogs
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def user_hash
|
55
|
+
url = "http://www.tumblr.com/api/authenticate"
|
56
|
+
@user_hash ||= Hash.from_xml(@access_token.get(url).body)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Twitter via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Twitter, 'consumerkey', 'consumersecret'
|
13
|
+
#
|
14
|
+
class Twitter < OmniAuth::Strategies::OAuth
|
15
|
+
# Initialize the middleware
|
16
|
+
#
|
17
|
+
# @option options [Boolean, true] :sign_in When true, use the "Sign in with Twitter" flow instead of the authorization flow.
|
18
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
19
|
+
client_options = {
|
20
|
+
:site => 'https://api.twitter.com'
|
21
|
+
}
|
22
|
+
|
23
|
+
options[:authorize_params] = {:force_login => 'true'} if options.delete(:force_login) == true
|
24
|
+
client_options[:authorize_path] = '/oauth/authenticate' unless options[:sign_in] == false
|
25
|
+
super(app, :twitter, consumer_key, consumer_secret, client_options, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def auth_hash
|
29
|
+
OmniAuth::Utils.deep_merge(super, {
|
30
|
+
'uid' => @access_token.params[:user_id],
|
31
|
+
'user_info' => user_info,
|
32
|
+
'extra' => {'user_hash' => user_hash}
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
def user_info
|
37
|
+
user_hash = self.user_hash
|
38
|
+
|
39
|
+
{
|
40
|
+
'nickname' => user_hash['screen_name'],
|
41
|
+
'name' => user_hash['name'] || user_hash['screen_name'],
|
42
|
+
'location' => user_hash['location'],
|
43
|
+
'image' => user_hash['profile_image_url'],
|
44
|
+
'description' => user_hash['description'],
|
45
|
+
'urls' => {
|
46
|
+
'Website' => user_hash['url'],
|
47
|
+
'Twitter' => 'http://twitter.com/' + user_hash['screen_name']
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_hash
|
53
|
+
@user_hash ||= MultiJson.decode(@access_token.get('/1/account/verify_credentials.json').body)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Typepad via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Typepad, 'consumerkey', 'consumersecret', :application_id => 'my_type_pad_application_id'
|
13
|
+
#
|
14
|
+
# application_id is required.
|
15
|
+
#
|
16
|
+
class TypePad < OmniAuth::Strategies::OAuth
|
17
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
18
|
+
|
19
|
+
# TypePad uses the application ID for one of the OAuth paths.
|
20
|
+
app_id = options[:application_id]
|
21
|
+
|
22
|
+
client_options = {
|
23
|
+
:site => 'https://www.typepad.com',
|
24
|
+
:request_token_path => '/secure/services/oauth/request_token',
|
25
|
+
:access_token_path => '/secure/services/oauth/access_token',
|
26
|
+
:authorize_path => "/secure/services/api/#{app_id}/oauth-approve",
|
27
|
+
:http_method => :get,
|
28
|
+
# You *must* use query_string for the token dance.
|
29
|
+
:scheme => :query_string
|
30
|
+
}
|
31
|
+
|
32
|
+
options.merge! :scheme => :query_string, :http_method => :get
|
33
|
+
|
34
|
+
super(app, :type_pad, consumer_key, consumer_secret, client_options, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def auth_hash
|
38
|
+
ui = user_info
|
39
|
+
OmniAuth::Utils.deep_merge(super, {
|
40
|
+
'uid' => ui['uid'],
|
41
|
+
'user_info' => ui,
|
42
|
+
'extra' => {'user_hash' => user_hash}
|
43
|
+
})
|
44
|
+
end
|
45
|
+
|
46
|
+
def user_info
|
47
|
+
user_hash = self.user_hash
|
48
|
+
|
49
|
+
{
|
50
|
+
'uid' => user_hash['urlId'],
|
51
|
+
'nickname' => user_hash['preferredUsername'],
|
52
|
+
'name' => user_hash['displayName'],
|
53
|
+
'image' => user_hash['avatarLink']['url'],
|
54
|
+
'description' => user_hash['aboutMe'],
|
55
|
+
'urls' => {'Profile' => user_hash['profilePageUrl']}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def user_hash
|
60
|
+
# For authenticated requests, you have to use header as your scheme.
|
61
|
+
# Failure to do so gives a unique response body - 'Auth is required'.
|
62
|
+
# 'Unauthorized' is the response body of a truly unauthorized request.
|
63
|
+
|
64
|
+
# Also note that API requests hit a different site than the OAuth dance.
|
65
|
+
r = self.consumer.request(
|
66
|
+
:get,
|
67
|
+
"https://api.typepad.com/users/@self.json",
|
68
|
+
@access_token,
|
69
|
+
:scheme => 'header'
|
70
|
+
)
|
71
|
+
|
72
|
+
@user_hash ||= MultiJson.decode(r.body)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Vimeo via OAuth and retrieve basic user information.
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
#
|
11
|
+
# use OmniAuth::Strategies::Vimeo, 'consumerkey', 'consumersecret'
|
12
|
+
#
|
13
|
+
class Vimeo < OmniAuth::Strategies::OAuth
|
14
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
15
|
+
opts = {
|
16
|
+
:site => 'http://vimeo.com',
|
17
|
+
:request_token_path => '/oauth/request_token',
|
18
|
+
:access_token_path => '/oauth/access_token',
|
19
|
+
:authorize_path => '/oauth/authorize'
|
20
|
+
}
|
21
|
+
super(app, :vimeo, consumer_key, consumer_secret, opts, options, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def auth_hash
|
25
|
+
user = user_hash['person']
|
26
|
+
OmniAuth::Utils.deep_merge(super, {
|
27
|
+
'uid' => user['id'],
|
28
|
+
'user_info' => user_info,
|
29
|
+
'extra' => { 'user_hash' => user }
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
def user_info
|
34
|
+
user = user_hash['person']
|
35
|
+
{
|
36
|
+
'nickname' => user['username'],
|
37
|
+
'name' => user['display_name'],
|
38
|
+
'location' => user['location'],
|
39
|
+
'description' => user['bio'],
|
40
|
+
'image' => user['portraits']['portrait'].select{|h| h['height'] == '300'}.first['_content'],
|
41
|
+
'urls' => {
|
42
|
+
'website' => user['url'],
|
43
|
+
'vimeo' => user['profileurl']
|
44
|
+
}
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def user_hash
|
49
|
+
url = "http://vimeo.com/api/rest/v2?method=vimeo.people.getInfo&format=json"
|
50
|
+
@user_hash ||= MultiJson.decode(@access_token.get(url).body)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Vkontakte utilizing OAuth 2.0 and retrieve
|
8
|
+
# basic user information.
|
9
|
+
# documentation available here:
|
10
|
+
# http://vkontakte.ru/developers.php?o=-17680044&p=Authorization&s=0
|
11
|
+
#
|
12
|
+
# @example Basic Usage
|
13
|
+
# use OmniAuth::Strategies::Vkontakte, 'API Key', 'Secret Key'
|
14
|
+
class Vkontakte < OAuth2
|
15
|
+
# @param [Rack Application] app standard middleware application parameter
|
16
|
+
# @param [String] api_key the application id as [registered in Vkontakte]
|
17
|
+
# @param [String] secret_key the application secret as [registered in Vkontakte]
|
18
|
+
def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
|
19
|
+
client_options = {
|
20
|
+
:site => 'https://vkontakte.ru',
|
21
|
+
:authorize_url => 'http://api.vkontakte.ru/oauth/authorize',
|
22
|
+
:access_token_url => 'https://api.vkontakte.ru/oauth/token'
|
23
|
+
}
|
24
|
+
|
25
|
+
super(app, :vkontakte, api_key, secret_key, client_options, options, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def user_data
|
31
|
+
# http://vkontakte.ru/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter
|
32
|
+
@fields ||= ['uid', 'first_name', 'last_name', 'nickname', 'domain', 'sex', 'city', 'country', 'timezone', 'photo', 'photo_big']
|
33
|
+
|
34
|
+
# http://vkontakte.ru/developers.php?o=-1&p=getProfiles
|
35
|
+
@data ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getProfiles?uid=#{@access_token['user_id']}&fields=#{@fields.join(',')}&access_token=#{@access_token.token}"))['response'][0]
|
36
|
+
|
37
|
+
# we need these 2 additional requests since vkontakte returns only ids of the City and Country
|
38
|
+
# http://vkontakte.ru/developers.php?o=-17680044&p=getCities
|
39
|
+
@city ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCities?cids=#{@data['city']}&access_token=#{@access_token.token}"))['response'][0]['name']
|
40
|
+
|
41
|
+
# http://vkontakte.ru/developers.php?o=-17680044&p=getCountries
|
42
|
+
@country ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCountries?cids=#{@data['country']}&access_token=#{@access_token}"))['response'][0]['name']
|
43
|
+
end
|
44
|
+
|
45
|
+
def request_phase
|
46
|
+
options[:response_type] ||= 'code'
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_info
|
51
|
+
{
|
52
|
+
'firstname' => @data['first_name'],
|
53
|
+
'last_name' => @data['last_name'],
|
54
|
+
'name' => "#{@data['first_name']} #{@data['last_name']}",
|
55
|
+
'nickname' => @data['nickname'],
|
56
|
+
'image' => @data['photo'],
|
57
|
+
'location' => "#{@country}, #{@city}",
|
58
|
+
'urls' => {
|
59
|
+
'Vkontakte' => "http://vkontakte.ru/#{@data['domain']}"
|
60
|
+
}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def user_hash
|
65
|
+
{
|
66
|
+
"user_hash" => {
|
67
|
+
"gender" => @data["sex"],
|
68
|
+
"timezone" => @data["timezone"],
|
69
|
+
"photo_big" => @data["photo_big"] # 200px maximum resolution of the avatar (http://vkontakte.ru/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter)
|
70
|
+
}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def auth_hash
|
75
|
+
user_data # process user's info
|
76
|
+
OmniAuth::Utils.deep_merge(super, {
|
77
|
+
'uid' => @data['uid'],
|
78
|
+
'user_info' => user_info,
|
79
|
+
'extra' => user_hash
|
80
|
+
})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class XAuth
|
7
|
+
include OmniAuth::Strategy
|
8
|
+
|
9
|
+
attr_reader :name
|
10
|
+
attr_accessor :consumer_key, :consumer_secret, :consumer_options
|
11
|
+
|
12
|
+
def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
|
13
|
+
self.consumer_key = consumer_key
|
14
|
+
self.consumer_secret = consumer_secret
|
15
|
+
self.consumer_options = consumer_options
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def request_phase
|
20
|
+
session['oauth'] ||= {}
|
21
|
+
if env['REQUEST_METHOD'] == 'GET'
|
22
|
+
get_credentials
|
23
|
+
else
|
24
|
+
session['omniauth.xauth'] = { 'x_auth_mode' => 'client_auth', 'x_auth_username' => request['username'], 'x_auth_password' => request['password'] }
|
25
|
+
redirect callback_path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_credentials
|
30
|
+
OmniAuth::Form.build(consumer_options[:title] || "xAuth Credentials") do
|
31
|
+
text_field 'Username', 'username'
|
32
|
+
password_field 'Password', 'password'
|
33
|
+
end.to_response
|
34
|
+
end
|
35
|
+
|
36
|
+
def consumer
|
37
|
+
::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_options] || {}))
|
38
|
+
end
|
39
|
+
|
40
|
+
def callback_phase
|
41
|
+
@access_token = consumer.get_access_token(nil, {}, session['omniauth.xauth'])
|
42
|
+
super
|
43
|
+
rescue ::Net::HTTPFatalError => e
|
44
|
+
fail!(:service_unavailable, e)
|
45
|
+
rescue ::OAuth::Unauthorized => e
|
46
|
+
fail!(:invalid_credentials, e)
|
47
|
+
rescue ::MultiJson::DecodeError => e
|
48
|
+
fail!(:invalid_response, e)
|
49
|
+
ensure
|
50
|
+
session['omniauth.xauth'] = nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def auth_hash
|
54
|
+
OmniAuth::Utils.deep_merge(super, {
|
55
|
+
'credentials' => {
|
56
|
+
'token' => @access_token.token,
|
57
|
+
'secret' => @access_token.secret
|
58
|
+
}, 'extra' => {
|
59
|
+
'access_token' => @access_token
|
60
|
+
}
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|