oa-oauth 0.2.6 → 0.3.0.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/lib/omniauth/oauth.rb +65 -47
- data/lib/omniauth/strategies/google_oauth2.rb +59 -0
- data/lib/omniauth/strategies/oauth.rb +8 -2
- data/lib/omniauth/strategies/oauth/blogger.rb +58 -0
- data/lib/omniauth/strategies/{dopplr.rb → oauth/dopplr.rb} +19 -21
- data/lib/omniauth/strategies/{douban.rb → oauth/douban.rb} +18 -18
- data/lib/omniauth/strategies/oauth/dropbox.rb +40 -0
- data/lib/omniauth/strategies/{evernote.rb → oauth/evernote.rb} +11 -13
- data/lib/omniauth/strategies/oauth/flattr.rb +47 -0
- data/lib/omniauth/strategies/oauth/flickr.rb +39 -0
- data/lib/omniauth/strategies/{goodreads.rb → oauth/goodreads.rb} +9 -9
- data/lib/omniauth/strategies/{google.rb → oauth/google.rb} +19 -20
- data/lib/omniauth/strategies/oauth/google_health.rb +71 -0
- data/lib/omniauth/strategies/oauth/google_health_sandbox.rb +74 -0
- data/lib/omniauth/strategies/oauth/hyves.rb +69 -0
- data/lib/omniauth/strategies/{identica.rb → oauth/identica.rb} +20 -16
- data/lib/omniauth/strategies/{linked_in.rb → oauth/linked_in.rb} +14 -14
- data/lib/omniauth/strategies/{meetup.rb → oauth/meetup.rb} +18 -16
- data/lib/omniauth/strategies/{miso.rb → oauth/miso.rb} +14 -7
- data/lib/omniauth/strategies/{netflix.rb → oauth/netflix.rb} +16 -14
- data/lib/omniauth/strategies/oauth/orkut.rb +63 -0
- data/lib/omniauth/strategies/oauth/plurk.rb +57 -0
- data/lib/omniauth/strategies/{qzone.rb → oauth/qzone.rb} +15 -12
- data/lib/omniauth/strategies/oauth/rdio.rb +48 -0
- data/lib/omniauth/strategies/oauth/smug_mug.rb +47 -0
- data/lib/omniauth/strategies/{t163.rb → oauth/t163.rb} +17 -17
- data/lib/omniauth/strategies/oauth/tqq.rb +63 -0
- data/lib/omniauth/strategies/oauth/trade_me.rb +50 -0
- data/lib/omniauth/strategies/oauth/trip_it.rb +24 -0
- data/lib/omniauth/strategies/{tsina.rb → oauth/tsina.rb} +21 -15
- data/lib/omniauth/strategies/{tsohu.rb → oauth/tsohu.rb} +15 -17
- data/lib/omniauth/strategies/{tumblr.rb → oauth/tumblr.rb} +13 -15
- data/lib/omniauth/strategies/{twitter.rb → oauth/twitter.rb} +17 -16
- data/lib/omniauth/strategies/{type_pad.rb → oauth/type_pad.rb} +18 -27
- data/lib/omniauth/strategies/{vimeo.rb → oauth/vimeo.rb} +18 -14
- data/lib/omniauth/strategies/{yahoo.rb → oauth/yahoo.rb} +17 -12
- data/lib/omniauth/strategies/{yammer.rb → oauth/yammer.rb} +17 -12
- data/lib/omniauth/strategies/{you_tube.rb → oauth/you_tube.rb} +16 -14
- data/lib/omniauth/strategies/oauth2.rb +7 -5
- data/lib/omniauth/strategies/oauth2/angellist.rb +57 -0
- data/lib/omniauth/strategies/oauth2/bitly.rb +43 -0
- data/lib/omniauth/strategies/oauth2/cobot.rb +54 -0
- data/lib/omniauth/strategies/{dailymile.rb → oauth2/dailymile.rb} +19 -20
- data/lib/omniauth/strategies/{doit.rb → oauth2/doit.rb} +18 -18
- data/lib/omniauth/strategies/{facebook.rb → oauth2/facebook.rb} +38 -21
- data/lib/omniauth/strategies/{foursquare.rb → oauth2/foursquare.rb} +20 -19
- data/lib/omniauth/strategies/{github.rb → oauth2/github.rb} +21 -19
- data/lib/omniauth/strategies/oauth2/glitch.rb +45 -0
- data/lib/omniauth/strategies/oauth2/gowalla.rb +72 -0
- data/lib/omniauth/strategies/{instagram.rb → oauth2/instagram.rb} +19 -17
- data/lib/omniauth/strategies/oauth2/liveid.rb +67 -0
- data/lib/omniauth/strategies/oauth2/mailchimp.rb +39 -0
- data/lib/omniauth/strategies/oauth2/mailru.rb +75 -0
- data/lib/omniauth/strategies/{mixi.rb → oauth2/mixi.rb} +23 -18
- data/lib/omniauth/strategies/{renren.rb → oauth2/renren.rb} +25 -23
- data/lib/omniauth/strategies/oauth2/salesforce.rb +48 -0
- data/lib/omniauth/strategies/oauth2/sound_cloud.rb +60 -0
- data/lib/omniauth/strategies/{taobao.rb → oauth2/taobao.rb} +24 -22
- data/lib/omniauth/strategies/{teambox.rb → oauth2/teambox.rb} +19 -17
- data/lib/omniauth/strategies/{thirty_seven_signals.rb → oauth2/thirty_seven_signals.rb} +17 -17
- data/lib/omniauth/strategies/oauth2/viadeo.rb +72 -0
- data/lib/omniauth/strategies/oauth2/vkontakte.rb +104 -0
- data/lib/omniauth/strategies/oauth2/we_pay.rb +48 -0
- data/lib/omniauth/strategies/xauth.rb +3 -3
- data/lib/omniauth/strategies/{instapaper.rb → xauth/instapaper.rb} +9 -12
- data/lib/omniauth/version.rb +3 -3
- data/oa-oauth.gemspec +17 -18
- data/spec/omniauth/strategies/{bitly_spec.rb → google_oauth2_spec.rb} +1 -1
- data/spec/omniauth/strategies/{dopplr_spec.rb → oauth/dopplr_spec.rb} +1 -1
- data/spec/omniauth/strategies/{douban_spec.rb → oauth/douban_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth/dropbox_spec.rb +5 -0
- data/spec/omniauth/strategies/{evernote_spec.rb → oauth/evernote_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth/flattr_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth/flickr_spec.rb +6 -0
- data/spec/omniauth/strategies/{goodreads_spec.rb → oauth/goodreads_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth/google_health_sandbox_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth/google_health_spec.rb +5 -0
- data/spec/omniauth/strategies/{google_spec.rb → oauth/google_spec.rb} +1 -1
- data/spec/omniauth/strategies/{hyves_spec.rb → oauth/hyves_spec.rb} +1 -1
- data/spec/omniauth/strategies/{identica_spec.rb → oauth/identica_spec.rb} +1 -1
- data/spec/omniauth/strategies/{linked_in_spec.rb → oauth/linked_in_spec.rb} +1 -1
- data/spec/omniauth/strategies/{meetup_spec.rb → oauth/meetup_spec.rb} +3 -3
- data/spec/omniauth/strategies/{miso_spec.rb → oauth/miso_spec.rb} +1 -1
- data/spec/omniauth/strategies/{netflix_spec.rb → oauth/netflix_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth/oauth_spec.rb +131 -0
- data/spec/omniauth/strategies/oauth/orkut_spec.rb +5 -0
- data/spec/omniauth/strategies/{plurk_spec.rb → oauth/plurk_spec.rb} +1 -1
- data/spec/omniauth/strategies/{rdio_spec.rb → oauth/rdio_spec.rb} +1 -1
- data/spec/omniauth/strategies/{smug_mug_spec.rb → oauth/smug_mug_spec.rb} +1 -1
- data/spec/omniauth/strategies/{t163_spec.rb → oauth/t163_spec.rb} +1 -1
- data/spec/omniauth/strategies/{trade_me_spec.rb → oauth/trade_me_spec.rb} +1 -1
- data/spec/omniauth/strategies/{trip_it_spec.rb → oauth/trip_it_spec.rb} +1 -1
- data/spec/omniauth/strategies/{tsina_spec.rb → oauth/tsina_spec.rb} +1 -1
- data/spec/omniauth/strategies/{tumblr_spec.rb → oauth/tumblr_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth/twitter_spec.rb +43 -0
- data/spec/omniauth/strategies/{type_pad_spec.rb → oauth/type_pad_spec.rb} +1 -1
- data/spec/omniauth/strategies/{vimeo_spec.rb → oauth/vimeo_spec.rb} +1 -1
- data/spec/omniauth/strategies/{yahoo_spec.rb → oauth/yahoo_spec.rb} +1 -1
- data/spec/omniauth/strategies/{yammer_spec.rb → oauth/yammer_spec.rb} +1 -1
- data/spec/omniauth/strategies/{you_tube_spec.rb → oauth/you_tube_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth2/angellist_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth2/bitly_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth2/cobot_spec.rb +5 -0
- data/spec/omniauth/strategies/{dailymile_spec.rb → oauth2/dailymile_spec.rb} +1 -1
- data/spec/omniauth/strategies/{doit_spec.rb → oauth2/doit_spec.rb} +1 -1
- data/spec/omniauth/strategies/{facebook_spec.rb → oauth2/facebook_spec.rb} +1 -1
- data/spec/omniauth/strategies/{foursquare_spec.rb → oauth2/foursquare_spec.rb} +1 -1
- data/spec/omniauth/strategies/{github_spec.rb → oauth2/github_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth2/glitch_spec.rb +5 -0
- data/spec/omniauth/strategies/{gowalla_spec.rb → oauth2/gowalla_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth2/instagram_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth2/liveid_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth2/mailchimp_spec.rb +6 -0
- data/spec/omniauth/strategies/{mailru_spec.rb → oauth2/mailru_spec.rb} +1 -1
- data/spec/omniauth/strategies/{salesforce_spec.rb → oauth2/salesforce_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth2/sound_cloud_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth2/taobao_spec.rb +5 -0
- data/spec/omniauth/strategies/{teambox_spec.rb → oauth2/teambox_spec.rb} +1 -1
- data/spec/omniauth/strategies/{thirty_seven_signals_spec.rb → oauth2/thirty_seven_signals_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth2/viadeo_spec.rb +5 -0
- data/spec/omniauth/strategies/{vkontakte_spec.rb → oauth2/vkontakte_spec.rb} +1 -1
- data/spec/omniauth/strategies/oauth2/we_pay_spec.rb +5 -0
- data/spec/spec_helper.rb +4 -0
- metadata +277 -151
- data/lib/omniauth/strategies/bitly.rb +0 -46
- data/lib/omniauth/strategies/gowalla.rb +0 -72
- data/lib/omniauth/strategies/hyves.rb +0 -67
- data/lib/omniauth/strategies/mailru.rb +0 -107
- data/lib/omniauth/strategies/plurk.rb +0 -58
- data/lib/omniauth/strategies/rdio.rb +0 -45
- data/lib/omniauth/strategies/salesforce.rb +0 -44
- data/lib/omniauth/strategies/smug_mug.rb +0 -42
- data/lib/omniauth/strategies/sound_cloud.rb +0 -46
- data/lib/omniauth/strategies/tqq.rb +0 -64
- data/lib/omniauth/strategies/trade_me.rb +0 -45
- data/lib/omniauth/strategies/trip_it.rb +0 -22
- data/lib/omniauth/strategies/vkontakte.rb +0 -87
- data/spec/omniauth/strategies/oauth2_spec.rb +0 -0
- data/spec/omniauth/strategies/oauth_spec.rb +0 -77
- data/spec/omniauth/strategies/sound_cloud_spec.rb +0 -5
- data/spec/omniauth/strategies/taobao_spec.rb +0 -5
- data/spec/omniauth/strategies/twitter_spec.rb +0 -20
|
@@ -4,35 +4,33 @@ require 'evernote'
|
|
|
4
4
|
|
|
5
5
|
module OmniAuth
|
|
6
6
|
module Strategies
|
|
7
|
-
#
|
|
8
7
|
# Authenticate to Evernote via OAuth and retrieve an access token for API usage
|
|
9
8
|
#
|
|
10
9
|
# Usage:
|
|
11
|
-
#
|
|
12
10
|
# use OmniAuth::Strategies::Evernote, 'consumerkey', 'consumersecret'
|
|
13
|
-
#
|
|
14
11
|
class Evernote < OmniAuth::Strategies::OAuth
|
|
15
12
|
# Initialize the Evernote strategy.
|
|
16
13
|
#
|
|
17
14
|
# @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
|
|
18
|
-
def initialize(app, consumer_key
|
|
15
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
19
16
|
client_options = {
|
|
20
|
-
:site => 'https://www.evernote.com',
|
|
21
|
-
:request_token_path => '/oauth',
|
|
22
17
|
:access_token_path => '/oauth',
|
|
23
18
|
:authorize_path => '/OAuth.action',
|
|
24
|
-
:oauth_signature_method => 'PLAINTEXT'
|
|
19
|
+
:oauth_signature_method => 'PLAINTEXT',
|
|
20
|
+
:request_token_path => '/oauth',
|
|
21
|
+
:site => 'https://www.evernote.com',
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
super(app, :evernote, consumer_key, consumer_secret, client_options, options, &block)
|
|
28
24
|
end
|
|
29
25
|
|
|
30
26
|
def auth_hash
|
|
31
|
-
OmniAuth::Utils.deep_merge(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
OmniAuth::Utils.deep_merge(
|
|
28
|
+
super, {
|
|
29
|
+
'uid' => user_data.id,
|
|
30
|
+
'user_info' => user_info,
|
|
31
|
+
'extra' => user_data,
|
|
32
|
+
}
|
|
33
|
+
)
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
def user_info
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_xml'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies
|
|
6
|
+
# Authenticate to Flattr via OAuth and retrieve basic user information.
|
|
7
|
+
# Usage:
|
|
8
|
+
# use OmniAuth::Strategies::Flattr, 'consumerkey', 'consumersecret'
|
|
9
|
+
class Flattr < OmniAuth::Strategies::OAuth
|
|
10
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
11
|
+
client_options = {
|
|
12
|
+
:site => 'https://api.flattr.com'
|
|
13
|
+
}
|
|
14
|
+
options[:authorize_params] = {:access_scope => "read,publish,click,extendedread"}
|
|
15
|
+
super(app, :flattr, consumer_key, consumer_secret, client_options, options, &block)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def auth_hash
|
|
19
|
+
ui = user_info
|
|
20
|
+
OmniAuth::Utils.deep_merge(super, {
|
|
21
|
+
'uid' => user_hash['id'],
|
|
22
|
+
'user_info' => ui,
|
|
23
|
+
'extra' => {'user_hash' => user_hash}
|
|
24
|
+
})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# user info according to schema
|
|
28
|
+
def user_info
|
|
29
|
+
{
|
|
30
|
+
'uid' => user_hash['id'],
|
|
31
|
+
'nickname' => user_hash['username'],
|
|
32
|
+
'first_name' => user_hash['firstname'],
|
|
33
|
+
'last_name' => user_hash['lastname'],
|
|
34
|
+
'name' => [user_hash['firstname'],user_hash['lastname']].reject{ |n| n.nil? || n.empty? }.join(' '),
|
|
35
|
+
'email' => user_hash['email'],
|
|
36
|
+
'language' => user_hash['language']
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# info as supplied by Flattr user summary
|
|
41
|
+
# response: {"flattr"=>{"version"=>"0.5", "user"=>{"id"=>"82597", "username"=>"foo", "firstname"=>"Foo", "lastname"=>"Bar", "email"=>"foo@bar.com", "city"=>"", "country"=>"", "gravatar"=>"", "url"=>"", "description"=>"", "thingcount"=>"1", "language"=>"en_GB"}}}
|
|
42
|
+
def user_hash
|
|
43
|
+
@user_hash ||= MultiXml.parse(@access_token.get('/rest/0.5/user/me').body)["flattr"]["user"]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies
|
|
6
|
+
|
|
7
|
+
class Flickr < OmniAuth::Strategies::OAuth
|
|
8
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
9
|
+
scope = options.delete(:scope) || 'read'
|
|
10
|
+
options[:authorize_params] ||= {}
|
|
11
|
+
options[:authorize_params][:perms] = scope
|
|
12
|
+
|
|
13
|
+
client_options = {
|
|
14
|
+
:access_token_path => "/services/oauth/access_token",
|
|
15
|
+
:authorize_path => "/services/oauth/authorize",
|
|
16
|
+
:request_token_path => "/services/oauth/request_token",
|
|
17
|
+
:site => "http://www.flickr.com"
|
|
18
|
+
}
|
|
19
|
+
super(app, :flickr, consumer_key, consumer_secret, client_options, options, &block)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def auth_hash
|
|
23
|
+
OmniAuth::Utils.deep_merge(
|
|
24
|
+
super, {
|
|
25
|
+
'uid' => @access_token.params["user_nsid"],
|
|
26
|
+
'user_info' => user_info
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def user_info
|
|
32
|
+
{
|
|
33
|
+
'username' => @access_token.params["username"],
|
|
34
|
+
'full_name' => @access_token.params["fullname"]
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -4,8 +4,7 @@ require 'omniauth/oauth'
|
|
|
4
4
|
module OmniAuth
|
|
5
5
|
module Strategies
|
|
6
6
|
class Goodreads < OmniAuth::Strategies::OAuth
|
|
7
|
-
|
|
8
|
-
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
|
7
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
9
8
|
client_options = {
|
|
10
9
|
:site => 'http://www.goodreads.com',
|
|
11
10
|
}
|
|
@@ -14,15 +13,17 @@ module OmniAuth
|
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
def auth_hash
|
|
17
|
-
hash =
|
|
16
|
+
hash = user_info(@access_token)
|
|
18
17
|
|
|
19
|
-
OmniAuth::Utils.deep_merge(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
OmniAuth::Utils.deep_merge(
|
|
19
|
+
super, {
|
|
20
|
+
'uid' => hash.delete('id'),
|
|
21
|
+
'user_info' => hash,
|
|
22
|
+
}
|
|
23
|
+
)
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
def
|
|
26
|
+
def user_info(access_token)
|
|
26
27
|
authenticated_user = MultiXml.parse(@access_token.get('/api/auth_user').body)
|
|
27
28
|
id = authenticated_user.xpath('GoodreadsResponse/user').attribute('id').value.to_i
|
|
28
29
|
response_doc = MultiXml.parse(open("http://www.goodreads.com/user/show/#{id}.xml?key=#{@consumer_key}").read)
|
|
@@ -41,4 +42,3 @@ module OmniAuth
|
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
end
|
|
44
|
-
|
|
@@ -3,37 +3,36 @@ require 'multi_json'
|
|
|
3
3
|
|
|
4
4
|
module OmniAuth
|
|
5
5
|
module Strategies
|
|
6
|
-
#
|
|
7
6
|
# Authenticate to Google via OAuth and retrieve basic
|
|
8
7
|
# user information.
|
|
9
8
|
#
|
|
10
9
|
# Usage:
|
|
11
|
-
#
|
|
12
10
|
# use OmniAuth::Strategies::Google, 'consumerkey', 'consumersecret'
|
|
13
|
-
#
|
|
14
11
|
class Google < OmniAuth::Strategies::OAuth
|
|
15
|
-
def initialize(app, consumer_key
|
|
12
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
16
13
|
client_options = {
|
|
17
|
-
:site => 'https://www.google.com',
|
|
18
|
-
:request_token_path => '/accounts/OAuthGetRequestToken',
|
|
19
14
|
:access_token_path => '/accounts/OAuthGetAccessToken',
|
|
20
|
-
:authorize_path => '/accounts/OAuthAuthorizeToken'
|
|
15
|
+
:authorize_path => '/accounts/OAuthAuthorizeToken',
|
|
16
|
+
:request_token_path => '/accounts/OAuthGetRequestToken',
|
|
17
|
+
:site => 'https://www.google.com',
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
options[:scope]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
super(app, :google, consumer_key, consumer_secret, client_options, options)
|
|
19
|
+
google_contacts_auth = 'www.google.com/m8/feeds'
|
|
20
|
+
options[:scope] ||= "https://#{google_contacts_auth}"
|
|
21
|
+
options[:scope] << " https://#{google_contacts_auth}" unless options[:scope] =~ %r[http[s]?:\/\/#{google_contacts_auth}]
|
|
22
|
+
super(app, :google, consumer_key, consumer_secret, client_options, options, &block)
|
|
28
23
|
end
|
|
29
24
|
|
|
30
25
|
def auth_hash
|
|
31
26
|
ui = user_info
|
|
32
|
-
OmniAuth::Utils.deep_merge(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
OmniAuth::Utils.deep_merge(
|
|
28
|
+
super, {
|
|
29
|
+
'uid' => ui['uid'],
|
|
30
|
+
'user_info' => ui,
|
|
31
|
+
'extra' => {
|
|
32
|
+
'user_hash' => user_hash,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
def user_info
|
|
@@ -45,7 +44,7 @@ module OmniAuth
|
|
|
45
44
|
{
|
|
46
45
|
'email' => email,
|
|
47
46
|
'uid' => email,
|
|
48
|
-
'name' => name
|
|
47
|
+
'name' => name,
|
|
49
48
|
}
|
|
50
49
|
end
|
|
51
50
|
|
|
@@ -57,7 +56,7 @@ module OmniAuth
|
|
|
57
56
|
# however. It will fail in the extremely rare case of a user who has
|
|
58
57
|
# a Google Account but has never even signed up for Gmail. This has
|
|
59
58
|
# not been seen in the field.
|
|
60
|
-
@user_hash ||= MultiJson.decode(@access_token.get(
|
|
59
|
+
@user_hash ||= MultiJson.decode(@access_token.get('https://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json').body)
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
# Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies
|
|
6
|
+
# Authenticate to Google via OAuth and retrieve basic
|
|
7
|
+
# user information.
|
|
8
|
+
#
|
|
9
|
+
# Usage:
|
|
10
|
+
# use OmniAuth::Strategies::Google, 'consumerkey', 'consumersecret'
|
|
11
|
+
class GoogleHealth < OmniAuth::Strategies::OAuth
|
|
12
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
13
|
+
client_options = {
|
|
14
|
+
:access_token_path => '/accounts/OAuthGetAccessToken',
|
|
15
|
+
:authorize_path => '/accounts/OAuthAuthorizeToken',
|
|
16
|
+
:request_token_path => '/accounts/OAuthGetRequestToken',
|
|
17
|
+
:site => 'https://www.google.com',
|
|
18
|
+
}
|
|
19
|
+
super(app, :google_health, consumer_key, consumer_secret, client_options, options, &block)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def auth_hash
|
|
23
|
+
ui = user_info
|
|
24
|
+
OmniAuth::Utils.deep_merge(
|
|
25
|
+
super, {
|
|
26
|
+
'uid' => ui['uid'],
|
|
27
|
+
'user_info' => ui,
|
|
28
|
+
'extra' => {
|
|
29
|
+
'user_hash' => user_hash,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def user_info
|
|
36
|
+
email = user_hash['feed']['id']['$t']
|
|
37
|
+
name = user_hash['feed']['author'].first['name']['$t']
|
|
38
|
+
name = email if name.strip == '(unknown)'
|
|
39
|
+
{
|
|
40
|
+
'email' => email,
|
|
41
|
+
'uid' => email,
|
|
42
|
+
'name' => name,
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def user_hash
|
|
47
|
+
# Google is very strict about keeping authorization and
|
|
48
|
+
# authentication separated.
|
|
49
|
+
# They give no endpoint to get a user's profile directly that I can
|
|
50
|
+
# find. We *can* get their name and email out of the contacts feed,
|
|
51
|
+
# however. It will fail in the extremely rare case of a user who has
|
|
52
|
+
# a Google Account but has never even signed up for Gmail. This has
|
|
53
|
+
# not been seen in the field.
|
|
54
|
+
@user_hash ||= MultiJson.decode(@access_token.get('http://www.google.com/health/feeds/profile/default/default?digest=true&alt=json').body)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call
|
|
58
|
+
def request_phase
|
|
59
|
+
request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://www.google.com/health/feeds'})
|
|
60
|
+
(session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
|
61
|
+
r = Rack::Response.new
|
|
62
|
+
if request_token.callback_confirmed?
|
|
63
|
+
r.redirect(request_token.authorize_url)
|
|
64
|
+
else
|
|
65
|
+
r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
|
|
66
|
+
end
|
|
67
|
+
r.finish
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
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 GoogleHealthSandbox < OmniAuth::Strategies::OAuth
|
|
15
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
16
|
+
client_options = {
|
|
17
|
+
:access_token_path => '/accounts/OAuthGetAccessToken',
|
|
18
|
+
:authorize_path => '/accounts/OAuthAuthorizeToken',
|
|
19
|
+
:request_token_path => '/accounts/OAuthGetRequestToken',
|
|
20
|
+
:site => 'https://www.google.com',
|
|
21
|
+
}
|
|
22
|
+
super(app, :google_health_sandbox, consumer_key, consumer_secret, client_options, options, &block)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def auth_hash
|
|
26
|
+
ui = user_info
|
|
27
|
+
OmniAuth::Utils.deep_merge(
|
|
28
|
+
super, {
|
|
29
|
+
'uid' => ui['uid'],
|
|
30
|
+
'user_info' => ui,
|
|
31
|
+
'extra' => {
|
|
32
|
+
'user_hash' => user_hash,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def user_info
|
|
39
|
+
email = user_hash['feed']['id']['$t']
|
|
40
|
+
name = user_hash['feed']['author'].first['name']['$t']
|
|
41
|
+
name = email if name.strip == '(unknown)'
|
|
42
|
+
{
|
|
43
|
+
'email' => email,
|
|
44
|
+
'uid' => email,
|
|
45
|
+
'name' => name,
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def user_hash
|
|
50
|
+
# Google is very strict about keeping authorization and
|
|
51
|
+
# authentication separated.
|
|
52
|
+
# They give no endpoint to get a user's profile directly that I can
|
|
53
|
+
# find. We *can* get their name and email out of the contacts feed,
|
|
54
|
+
# however. It will fail in the extremely rare case of a user who has
|
|
55
|
+
# a Google Account but has never even signed up for Gmail. This has
|
|
56
|
+
# not been seen in the field.
|
|
57
|
+
@user_hash ||= MultiJson.decode(@access_token.get('http://www.google.com/h9/feeds/profile/default/default?digest=true&oauth_signature_method=RSA-SHA1&oauth_version=1.0').body)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call
|
|
61
|
+
def request_phase
|
|
62
|
+
request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://www.google.com/h9/feeds'})
|
|
63
|
+
(session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
|
64
|
+
r = Rack::Response.new
|
|
65
|
+
if request_token.callback_confirmed?
|
|
66
|
+
r.redirect(request_token.authorize_url)
|
|
67
|
+
else
|
|
68
|
+
r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
|
|
69
|
+
end
|
|
70
|
+
r.finish
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies
|
|
6
|
+
class Hyves < OmniAuth::Strategies::OAuth
|
|
7
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
|
8
|
+
options = {
|
|
9
|
+
:methods => 'users.get,friends.get,wwws.create',
|
|
10
|
+
:expirationtype => 'default'
|
|
11
|
+
}.merge(options)
|
|
12
|
+
|
|
13
|
+
client_options = {
|
|
14
|
+
:authorize_path => 'http://www.hyves.nl/api/authorize',
|
|
15
|
+
:access_token_path => access_token_path,
|
|
16
|
+
:http_method => :get,
|
|
17
|
+
:request_token_path => request_token_path(options),
|
|
18
|
+
:scheme => :header,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
super(app, :hyves, consumer_key, consumer_secret, client_options, options, &block)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def auth_hash
|
|
25
|
+
hash = user_hash(@access_token)
|
|
26
|
+
{
|
|
27
|
+
'provider' => 'hyves',
|
|
28
|
+
'uid' => hash['userid'],
|
|
29
|
+
'user_info' => {
|
|
30
|
+
'name' => "#{hash['firstname']} #{hash['lastname']}",
|
|
31
|
+
'first_name' => hash['firstname'],
|
|
32
|
+
'last_name' => hash['lastname'],
|
|
33
|
+
},
|
|
34
|
+
'credentials' => {
|
|
35
|
+
'token' => @access_token.token,
|
|
36
|
+
'secret' => @access_token.secret,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def user_hash(access_token)
|
|
42
|
+
rsp = MultiJson.decode(access_token.get("http://data.hyves-api.nl/?userid=#{access_token.params[:userid]}&ha_method=users.get&#{default_options}").body)
|
|
43
|
+
rsp['user'].first
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def request_token_path(options)
|
|
47
|
+
options['ha_method'] = 'auth.requesttoken'
|
|
48
|
+
options['strict_oauth_spec_response'] = true
|
|
49
|
+
"http://data.hyves-api.nl/?#{to_params(options)}&#{default_options}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def access_token_path
|
|
53
|
+
"http://data.hyves-api.nl/?#{access_token_options}&#{default_options}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def default_options
|
|
57
|
+
to_params({:ha_version => '2.0', :ha_format => 'json', :ha_fancylayout => false})
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def access_token_options
|
|
61
|
+
to_params({:ha_method => 'auth.accesstoken', :strict_oauth_spec_response => true})
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def to_params(options)
|
|
65
|
+
options.collect{|key, value| "#{key}=#{value}"}.join('&')
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|