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,53 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Dopplr via OAuth and retrieve an access token for API usage
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
#
|
11
|
+
# use OmniAuth::Strategies::Dopplr, 'consumerkey', 'consumersecret'
|
12
|
+
#
|
13
|
+
class Dopplr < OmniAuth::Strategies::OAuth
|
14
|
+
# Initialize the Dopplr strategy.
|
15
|
+
#
|
16
|
+
# @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
|
17
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
18
|
+
client_options = {
|
19
|
+
:site => 'https://www.dopplr.com',
|
20
|
+
:request_token_path => "/oauth/request_token",
|
21
|
+
:access_token_path => "/oauth/access_token",
|
22
|
+
:authorize_path => "/oauth/authorize"
|
23
|
+
}
|
24
|
+
|
25
|
+
super(app, :dopplr, consumer_key, consumer_secret, client_options, options, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def user_data
|
29
|
+
@data ||= MultiJson.decode(@access_token.get('/oauthapi/whoami').body)['whoami']
|
30
|
+
end
|
31
|
+
|
32
|
+
def user_info
|
33
|
+
{
|
34
|
+
'nickname' => user_data["nick"],
|
35
|
+
'first_name' => user_data["forename"],
|
36
|
+
'last_name' => user_data["surname"],
|
37
|
+
'name' => "#{user_data['forename']} #{user_data['surname']}",
|
38
|
+
'urls' => {
|
39
|
+
'Dopplr' => user_data["dopplr_url"],
|
40
|
+
'DopplrMobile' => user_data["mobile_url"],
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def auth_hash
|
46
|
+
OmniAuth::Utils.deep_merge(super, {
|
47
|
+
'uid' => user_data['nick'],
|
48
|
+
'user_info' => user_info
|
49
|
+
})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Douban via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Douban, 'APIKey', 'APIKeySecret'
|
13
|
+
#
|
14
|
+
class Douban < OmniAuth::Strategies::OAuth
|
15
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
16
|
+
# Although in OAuth spec the :realm parameter is optional,
|
17
|
+
# it is required for Douban.
|
18
|
+
client_options = {
|
19
|
+
:site => 'http://www.douban.com',
|
20
|
+
:request_token_path => '/service/auth/request_token',
|
21
|
+
:access_token_path => '/service/auth/access_token',
|
22
|
+
:authorize_path => '/service/auth/authorize',
|
23
|
+
:realm => 'OmniAuth'
|
24
|
+
}
|
25
|
+
|
26
|
+
super(app, :douban, consumer_key, consumer_secret, client_options, options, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def auth_hash
|
30
|
+
OmniAuth::Utils.deep_merge(super, {
|
31
|
+
'uid' => @access_token.params[:douban_user_id],
|
32
|
+
'user_info' => user_info,
|
33
|
+
'extra' => {'user_hash' => user_hash}
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
def user_info
|
38
|
+
user_hash = self.user_hash
|
39
|
+
|
40
|
+
location = user_hash['location'] ? user_hash['location']['$t'] : nil
|
41
|
+
image = user_hash['link'].find {|l| l['@rel'] == 'icon' }['@href']
|
42
|
+
douban_url = user_hash['link'].find {|l| l['@rel'] == 'alternate' }['@href']
|
43
|
+
{
|
44
|
+
'username' => user_hash['db:uid']['$t'],
|
45
|
+
'name' => user_hash['title']['$t'],
|
46
|
+
'location' => location,
|
47
|
+
'image' => image,
|
48
|
+
'description' => user_hash['content']['$t'],
|
49
|
+
'urls' => {
|
50
|
+
'Douban' => douban_url
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def user_hash
|
56
|
+
@user_hash ||= MultiJson.decode(@access_token.get('http://api.douban.com/people/%40me?alt=json').body)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'evernote'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
#
|
8
|
+
# Authenticate to Evernote via OAuth and retrieve an access token for API usage
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Evernote, 'consumerkey', 'consumersecret'
|
13
|
+
#
|
14
|
+
class Evernote < OmniAuth::Strategies::OAuth
|
15
|
+
# Initialize the Evernote strategy.
|
16
|
+
#
|
17
|
+
# @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
|
18
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
19
|
+
client_options = {
|
20
|
+
:site => 'https://www.evernote.com',
|
21
|
+
:request_token_path => '/oauth',
|
22
|
+
:access_token_path => '/oauth',
|
23
|
+
:authorize_path => '/OAuth.action',
|
24
|
+
:oauth_signature_method => 'PLAINTEXT'
|
25
|
+
}
|
26
|
+
|
27
|
+
super(app, :evernote, consumer_key, consumer_secret, client_options, options, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def auth_hash
|
31
|
+
OmniAuth::Utils.deep_merge(super, {
|
32
|
+
'uid' => user_data.id,
|
33
|
+
'user_info' => user_info,
|
34
|
+
'extra' => user_data
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_info
|
39
|
+
{
|
40
|
+
'name' => user_data.name,
|
41
|
+
'nickname' => user_data.username,
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def user_data
|
46
|
+
@user_data ||= begin
|
47
|
+
user_store_url = consumer.site + '/edam/user'
|
48
|
+
client = ::Evernote::Client.new(::Evernote::EDAM::UserStore::UserStore::Client, user_store_url, {})
|
49
|
+
client.getUser(@access_token.token)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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::Facebook, 'client_id', 'client_secret'
|
11
|
+
class Facebook < OAuth2
|
12
|
+
# @param [Rack Application] app standard middleware application parameter
|
13
|
+
# @param [String] client_id the application id as [registered on Facebook](http://www.facebook.com/developers/)
|
14
|
+
# @param [String] client_secret the application secret as registered on Facebook
|
15
|
+
# @option options [String] :scope ('email,offline_access') comma-separated extended permissions such as `email` and `manage_pages`
|
16
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
17
|
+
super(app, :facebook, client_id, client_secret, {:site => 'https://graph.facebook.com/'}, options, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_data
|
21
|
+
@data ||= MultiJson.decode(@access_token.get('/me', {}, { "Accept-Language" => "en-us,en;"}))
|
22
|
+
end
|
23
|
+
|
24
|
+
def request_phase
|
25
|
+
options[:scope] ||= "email,offline_access"
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_access_token
|
30
|
+
if facebook_session.nil? || facebook_session.empty?
|
31
|
+
super
|
32
|
+
else
|
33
|
+
@access_token = ::OAuth2::AccessToken.new(client, facebook_session['access_token'])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def facebook_session
|
38
|
+
session_cookie = request.cookies["fbs_#{client.id}"]
|
39
|
+
if session_cookie
|
40
|
+
@facebook_session ||= Rack::Utils.parse_query(request.cookies["fbs_#{client.id}"].gsub('"', ''))
|
41
|
+
else
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def user_info
|
47
|
+
{
|
48
|
+
'nickname' => user_data["link"].split('/').last,
|
49
|
+
'email' => (user_data["email"] if user_data["email"]),
|
50
|
+
'first_name' => user_data["first_name"],
|
51
|
+
'last_name' => user_data["last_name"],
|
52
|
+
'name' => "#{user_data['first_name']} #{user_data['last_name']}",
|
53
|
+
'image' => "http://graph.facebook.com/#{user_data['id']}/picture?type=square",
|
54
|
+
'urls' => {
|
55
|
+
'Facebook' => user_data["link"],
|
56
|
+
'Website' => user_data["website"],
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def auth_hash
|
62
|
+
OmniAuth::Utils.deep_merge(super, {
|
63
|
+
'uid' => user_data['id'],
|
64
|
+
'user_info' => user_info,
|
65
|
+
'extra' => {'user_hash' => user_data}
|
66
|
+
})
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Foursquare < OAuth2
|
7
|
+
# Initialize the middleware
|
8
|
+
#
|
9
|
+
# @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
|
10
|
+
# @option options [Boolean, false] :mobile When true, use the mobile sign-in interface.
|
11
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
12
|
+
options[:sign_in] ||= true
|
13
|
+
super(app, :foursquare, client_id, client_secret, {
|
14
|
+
:site => "https://api.foursquare.com/v2",
|
15
|
+
:authorize_url => authorize_url(options),
|
16
|
+
:access_token_url => "https://foursquare.com/oauth2/access_token"
|
17
|
+
}, options, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorize_url(options)
|
21
|
+
"https://foursquare.com/#{'mobile/' if options[:mobile]}oauth2/#{options[:sign_in] ? 'authenticate' : 'authorize'}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def user_data
|
25
|
+
@data ||= MultiJson.decode(@access_token.get(client.site+'/users/self', {'oauth_token' => @access_token.token}))
|
26
|
+
end
|
27
|
+
|
28
|
+
def request_phase
|
29
|
+
options[:response_type] ||= 'code'
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def callback_phase
|
34
|
+
options[:grant_type] ||= 'authorization_code'
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_info
|
39
|
+
{
|
40
|
+
'nickname' => user_data['response']['user']['contact']['twitter'],
|
41
|
+
'first_name' => user_data['response']['user']['firstName'],
|
42
|
+
'last_name' => user_data['response']['user']['lastName'],
|
43
|
+
'email' => user_data['response']['user']['contact']['email'],
|
44
|
+
'name' => "#{user_data['response']['user']['firstName']} #{user_data['response']['user']['lastName']}".strip,
|
45
|
+
# 'location' => user_data['response']['user']['location'],
|
46
|
+
'image' => user_data['response']['user']['photo'],
|
47
|
+
# 'description' => user_data['response']['user']['description'],
|
48
|
+
'phone' => user_data['response']['user']['contact']['phone'],
|
49
|
+
'urls' => {}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def auth_hash
|
54
|
+
OmniAuth::Utils.deep_merge(super, {
|
55
|
+
'uid' => user_data['response']['user']['id'],
|
56
|
+
'user_info' => user_info,
|
57
|
+
'extra' => {'user_hash' => user_data['response']['user']}
|
58
|
+
})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
# OAuth 2.0 based authentication with GitHub. In order to
|
7
|
+
# sign up for an application, you need to [register an application](http://github.com/account/applications/new)
|
8
|
+
# and provide the proper credentials to this middleware.
|
9
|
+
class GitHub < OAuth2
|
10
|
+
# @param [Rack Application] app standard middleware application argument
|
11
|
+
# @param [String] client_id the application ID for your client
|
12
|
+
# @param [String] client_secret the application secret
|
13
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
14
|
+
client_options = {
|
15
|
+
:site => 'https://github.com/',
|
16
|
+
:authorize_path => '/login/oauth/authorize',
|
17
|
+
:access_token_path => '/login/oauth/access_token'
|
18
|
+
}
|
19
|
+
|
20
|
+
super(app, :github, client_id, client_secret, client_options, options, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def user_data
|
26
|
+
@data ||= MultiJson.decode(@access_token.get('/api/v2/json/user/show'))['user']
|
27
|
+
end
|
28
|
+
|
29
|
+
def user_info
|
30
|
+
{
|
31
|
+
'nickname' => user_data["login"],
|
32
|
+
'email' => user_data['email'],
|
33
|
+
'name' => user_data['name'],
|
34
|
+
'urls' => {
|
35
|
+
'GitHub' => "http://github.com/#{user_data['login']}",
|
36
|
+
'Blog' => user_data["blog"],
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def auth_hash
|
42
|
+
OmniAuth::Utils.deep_merge(super, {
|
43
|
+
'uid' => user_data['id'],
|
44
|
+
'user_info' => user_info,
|
45
|
+
'extra' => {'user_hash' => user_data}
|
46
|
+
})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'multi_xml'
|
2
|
+
require 'omniauth/oauth'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Goodreads < OmniAuth::Strategies::OAuth
|
7
|
+
|
8
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
9
|
+
client_options = {
|
10
|
+
:site => 'http://www.goodreads.com',
|
11
|
+
}
|
12
|
+
@consumer_key = consumer_key
|
13
|
+
super(app, :goodreads, consumer_key, consumer_secret, client_options, options, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def auth_hash
|
17
|
+
hash = user_hash(@access_token)
|
18
|
+
|
19
|
+
OmniAuth::Utils.deep_merge(super, {
|
20
|
+
'uid' => hash.delete('id'),
|
21
|
+
'user_info' => hash
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_hash(access_token)
|
26
|
+
authenticated_user = MultiXml.parse(@access_token.get('/api/auth_user').body)
|
27
|
+
id = authenticated_user.xpath('GoodreadsResponse/user').attribute('id').value.to_i
|
28
|
+
response_doc = MultiXml.parse(open("http://www.goodreads.com/user/show/#{id}.xml?key=#{@consumer_key}").read)
|
29
|
+
user = response_doc.xpath('GoodreadsResponse/user')
|
30
|
+
|
31
|
+
hash = {
|
32
|
+
'id' => id,
|
33
|
+
'name' => user.xpath('name').text,
|
34
|
+
'user_name' => user.xpath('user_name').text,
|
35
|
+
'image_url' => user.xpath('image_url').text,
|
36
|
+
'about' => user.xpath('about').text,
|
37
|
+
'location' => user.xpath('location').text,
|
38
|
+
'website' => user.xpath('website').text,
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Google via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Google, 'consumerkey', 'consumersecret'
|
13
|
+
#
|
14
|
+
class Google < OmniAuth::Strategies::OAuth
|
15
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
16
|
+
client_options = {
|
17
|
+
:site => 'https://www.google.com',
|
18
|
+
:request_token_path => '/accounts/OAuthGetRequestToken',
|
19
|
+
:access_token_path => '/accounts/OAuthGetAccessToken',
|
20
|
+
:authorize_path => '/accounts/OAuthAuthorizeToken'
|
21
|
+
}
|
22
|
+
|
23
|
+
google_contacts_auth = "http://www.google.com/m8/feeds"
|
24
|
+
options[:scope] ||= google_contacts_auth
|
25
|
+
options[:scope] << " #{google_contacts_auth}" unless options[:scope].include?(google_contacts_auth)
|
26
|
+
|
27
|
+
super(app, :google, consumer_key, consumer_secret, client_options, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def auth_hash
|
31
|
+
ui = user_info
|
32
|
+
OmniAuth::Utils.deep_merge(super, {
|
33
|
+
'uid' => ui['uid'],
|
34
|
+
'user_info' => ui,
|
35
|
+
'extra' => {'user_hash' => user_hash}
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
def user_info
|
40
|
+
email = user_hash['feed']['id']['$t']
|
41
|
+
|
42
|
+
name = user_hash['feed']['author'].first['name']['$t']
|
43
|
+
name = email if name.strip == '(unknown)'
|
44
|
+
|
45
|
+
{
|
46
|
+
'email' => email,
|
47
|
+
'uid' => email,
|
48
|
+
'name' => name
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_hash
|
53
|
+
# Google is very strict about keeping authorization and
|
54
|
+
# authentication separated.
|
55
|
+
# They give no endpoint to get a user's profile directly that I can
|
56
|
+
# find. We *can* get their name and email out of the contacts feed,
|
57
|
+
# however. It will fail in the extremely rare case of a user who has
|
58
|
+
# a Google Account but has never even signed up for Gmail. This has
|
59
|
+
# not been seen in the field.
|
60
|
+
@user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json").body)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call
|
64
|
+
def request_phase
|
65
|
+
request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => options[:scope]})
|
66
|
+
session['oauth'] ||= {}
|
67
|
+
session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
68
|
+
r = Rack::Response.new
|
69
|
+
|
70
|
+
if request_token.callback_confirmed?
|
71
|
+
r.redirect(request_token.authorize_url)
|
72
|
+
else
|
73
|
+
r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
|
74
|
+
end
|
75
|
+
|
76
|
+
r.finish
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|