oa-oauth 0.2.6 → 0.3.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/Gemfile +4 -0
  2. data/lib/omniauth/oauth.rb +65 -47
  3. data/lib/omniauth/strategies/google_oauth2.rb +59 -0
  4. data/lib/omniauth/strategies/oauth.rb +8 -2
  5. data/lib/omniauth/strategies/oauth/blogger.rb +58 -0
  6. data/lib/omniauth/strategies/{dopplr.rb → oauth/dopplr.rb} +19 -21
  7. data/lib/omniauth/strategies/{douban.rb → oauth/douban.rb} +18 -18
  8. data/lib/omniauth/strategies/oauth/dropbox.rb +40 -0
  9. data/lib/omniauth/strategies/{evernote.rb → oauth/evernote.rb} +11 -13
  10. data/lib/omniauth/strategies/oauth/flattr.rb +47 -0
  11. data/lib/omniauth/strategies/oauth/flickr.rb +39 -0
  12. data/lib/omniauth/strategies/{goodreads.rb → oauth/goodreads.rb} +9 -9
  13. data/lib/omniauth/strategies/{google.rb → oauth/google.rb} +19 -20
  14. data/lib/omniauth/strategies/oauth/google_health.rb +71 -0
  15. data/lib/omniauth/strategies/oauth/google_health_sandbox.rb +74 -0
  16. data/lib/omniauth/strategies/oauth/hyves.rb +69 -0
  17. data/lib/omniauth/strategies/{identica.rb → oauth/identica.rb} +20 -16
  18. data/lib/omniauth/strategies/{linked_in.rb → oauth/linked_in.rb} +14 -14
  19. data/lib/omniauth/strategies/{meetup.rb → oauth/meetup.rb} +18 -16
  20. data/lib/omniauth/strategies/{miso.rb → oauth/miso.rb} +14 -7
  21. data/lib/omniauth/strategies/{netflix.rb → oauth/netflix.rb} +16 -14
  22. data/lib/omniauth/strategies/oauth/orkut.rb +63 -0
  23. data/lib/omniauth/strategies/oauth/plurk.rb +57 -0
  24. data/lib/omniauth/strategies/{qzone.rb → oauth/qzone.rb} +15 -12
  25. data/lib/omniauth/strategies/oauth/rdio.rb +48 -0
  26. data/lib/omniauth/strategies/oauth/smug_mug.rb +47 -0
  27. data/lib/omniauth/strategies/{t163.rb → oauth/t163.rb} +17 -17
  28. data/lib/omniauth/strategies/oauth/tqq.rb +63 -0
  29. data/lib/omniauth/strategies/oauth/trade_me.rb +50 -0
  30. data/lib/omniauth/strategies/oauth/trip_it.rb +24 -0
  31. data/lib/omniauth/strategies/{tsina.rb → oauth/tsina.rb} +21 -15
  32. data/lib/omniauth/strategies/{tsohu.rb → oauth/tsohu.rb} +15 -17
  33. data/lib/omniauth/strategies/{tumblr.rb → oauth/tumblr.rb} +13 -15
  34. data/lib/omniauth/strategies/{twitter.rb → oauth/twitter.rb} +17 -16
  35. data/lib/omniauth/strategies/{type_pad.rb → oauth/type_pad.rb} +18 -27
  36. data/lib/omniauth/strategies/{vimeo.rb → oauth/vimeo.rb} +18 -14
  37. data/lib/omniauth/strategies/{yahoo.rb → oauth/yahoo.rb} +17 -12
  38. data/lib/omniauth/strategies/{yammer.rb → oauth/yammer.rb} +17 -12
  39. data/lib/omniauth/strategies/{you_tube.rb → oauth/you_tube.rb} +16 -14
  40. data/lib/omniauth/strategies/oauth2.rb +7 -5
  41. data/lib/omniauth/strategies/oauth2/angellist.rb +57 -0
  42. data/lib/omniauth/strategies/oauth2/bitly.rb +43 -0
  43. data/lib/omniauth/strategies/oauth2/cobot.rb +54 -0
  44. data/lib/omniauth/strategies/{dailymile.rb → oauth2/dailymile.rb} +19 -20
  45. data/lib/omniauth/strategies/{doit.rb → oauth2/doit.rb} +18 -18
  46. data/lib/omniauth/strategies/{facebook.rb → oauth2/facebook.rb} +38 -21
  47. data/lib/omniauth/strategies/{foursquare.rb → oauth2/foursquare.rb} +20 -19
  48. data/lib/omniauth/strategies/{github.rb → oauth2/github.rb} +21 -19
  49. data/lib/omniauth/strategies/oauth2/glitch.rb +45 -0
  50. data/lib/omniauth/strategies/oauth2/gowalla.rb +72 -0
  51. data/lib/omniauth/strategies/{instagram.rb → oauth2/instagram.rb} +19 -17
  52. data/lib/omniauth/strategies/oauth2/liveid.rb +67 -0
  53. data/lib/omniauth/strategies/oauth2/mailchimp.rb +39 -0
  54. data/lib/omniauth/strategies/oauth2/mailru.rb +75 -0
  55. data/lib/omniauth/strategies/{mixi.rb → oauth2/mixi.rb} +23 -18
  56. data/lib/omniauth/strategies/{renren.rb → oauth2/renren.rb} +25 -23
  57. data/lib/omniauth/strategies/oauth2/salesforce.rb +48 -0
  58. data/lib/omniauth/strategies/oauth2/sound_cloud.rb +60 -0
  59. data/lib/omniauth/strategies/{taobao.rb → oauth2/taobao.rb} +24 -22
  60. data/lib/omniauth/strategies/{teambox.rb → oauth2/teambox.rb} +19 -17
  61. data/lib/omniauth/strategies/{thirty_seven_signals.rb → oauth2/thirty_seven_signals.rb} +17 -17
  62. data/lib/omniauth/strategies/oauth2/viadeo.rb +72 -0
  63. data/lib/omniauth/strategies/oauth2/vkontakte.rb +104 -0
  64. data/lib/omniauth/strategies/oauth2/we_pay.rb +48 -0
  65. data/lib/omniauth/strategies/xauth.rb +3 -3
  66. data/lib/omniauth/strategies/{instapaper.rb → xauth/instapaper.rb} +9 -12
  67. data/lib/omniauth/version.rb +3 -3
  68. data/oa-oauth.gemspec +17 -18
  69. data/spec/omniauth/strategies/{bitly_spec.rb → google_oauth2_spec.rb} +1 -1
  70. data/spec/omniauth/strategies/{dopplr_spec.rb → oauth/dopplr_spec.rb} +1 -1
  71. data/spec/omniauth/strategies/{douban_spec.rb → oauth/douban_spec.rb} +1 -1
  72. data/spec/omniauth/strategies/oauth/dropbox_spec.rb +5 -0
  73. data/spec/omniauth/strategies/{evernote_spec.rb → oauth/evernote_spec.rb} +1 -1
  74. data/spec/omniauth/strategies/oauth/flattr_spec.rb +5 -0
  75. data/spec/omniauth/strategies/oauth/flickr_spec.rb +6 -0
  76. data/spec/omniauth/strategies/{goodreads_spec.rb → oauth/goodreads_spec.rb} +1 -1
  77. data/spec/omniauth/strategies/oauth/google_health_sandbox_spec.rb +5 -0
  78. data/spec/omniauth/strategies/oauth/google_health_spec.rb +5 -0
  79. data/spec/omniauth/strategies/{google_spec.rb → oauth/google_spec.rb} +1 -1
  80. data/spec/omniauth/strategies/{hyves_spec.rb → oauth/hyves_spec.rb} +1 -1
  81. data/spec/omniauth/strategies/{identica_spec.rb → oauth/identica_spec.rb} +1 -1
  82. data/spec/omniauth/strategies/{linked_in_spec.rb → oauth/linked_in_spec.rb} +1 -1
  83. data/spec/omniauth/strategies/{meetup_spec.rb → oauth/meetup_spec.rb} +3 -3
  84. data/spec/omniauth/strategies/{miso_spec.rb → oauth/miso_spec.rb} +1 -1
  85. data/spec/omniauth/strategies/{netflix_spec.rb → oauth/netflix_spec.rb} +1 -1
  86. data/spec/omniauth/strategies/oauth/oauth_spec.rb +131 -0
  87. data/spec/omniauth/strategies/oauth/orkut_spec.rb +5 -0
  88. data/spec/omniauth/strategies/{plurk_spec.rb → oauth/plurk_spec.rb} +1 -1
  89. data/spec/omniauth/strategies/{rdio_spec.rb → oauth/rdio_spec.rb} +1 -1
  90. data/spec/omniauth/strategies/{smug_mug_spec.rb → oauth/smug_mug_spec.rb} +1 -1
  91. data/spec/omniauth/strategies/{t163_spec.rb → oauth/t163_spec.rb} +1 -1
  92. data/spec/omniauth/strategies/{trade_me_spec.rb → oauth/trade_me_spec.rb} +1 -1
  93. data/spec/omniauth/strategies/{trip_it_spec.rb → oauth/trip_it_spec.rb} +1 -1
  94. data/spec/omniauth/strategies/{tsina_spec.rb → oauth/tsina_spec.rb} +1 -1
  95. data/spec/omniauth/strategies/{tumblr_spec.rb → oauth/tumblr_spec.rb} +1 -1
  96. data/spec/omniauth/strategies/oauth/twitter_spec.rb +43 -0
  97. data/spec/omniauth/strategies/{type_pad_spec.rb → oauth/type_pad_spec.rb} +1 -1
  98. data/spec/omniauth/strategies/{vimeo_spec.rb → oauth/vimeo_spec.rb} +1 -1
  99. data/spec/omniauth/strategies/{yahoo_spec.rb → oauth/yahoo_spec.rb} +1 -1
  100. data/spec/omniauth/strategies/{yammer_spec.rb → oauth/yammer_spec.rb} +1 -1
  101. data/spec/omniauth/strategies/{you_tube_spec.rb → oauth/you_tube_spec.rb} +1 -1
  102. data/spec/omniauth/strategies/oauth2/angellist_spec.rb +5 -0
  103. data/spec/omniauth/strategies/oauth2/bitly_spec.rb +5 -0
  104. data/spec/omniauth/strategies/oauth2/cobot_spec.rb +5 -0
  105. data/spec/omniauth/strategies/{dailymile_spec.rb → oauth2/dailymile_spec.rb} +1 -1
  106. data/spec/omniauth/strategies/{doit_spec.rb → oauth2/doit_spec.rb} +1 -1
  107. data/spec/omniauth/strategies/{facebook_spec.rb → oauth2/facebook_spec.rb} +1 -1
  108. data/spec/omniauth/strategies/{foursquare_spec.rb → oauth2/foursquare_spec.rb} +1 -1
  109. data/spec/omniauth/strategies/{github_spec.rb → oauth2/github_spec.rb} +1 -1
  110. data/spec/omniauth/strategies/oauth2/glitch_spec.rb +5 -0
  111. data/spec/omniauth/strategies/{gowalla_spec.rb → oauth2/gowalla_spec.rb} +1 -1
  112. data/spec/omniauth/strategies/oauth2/instagram_spec.rb +5 -0
  113. data/spec/omniauth/strategies/oauth2/liveid_spec.rb +5 -0
  114. data/spec/omniauth/strategies/oauth2/mailchimp_spec.rb +6 -0
  115. data/spec/omniauth/strategies/{mailru_spec.rb → oauth2/mailru_spec.rb} +1 -1
  116. data/spec/omniauth/strategies/{salesforce_spec.rb → oauth2/salesforce_spec.rb} +1 -1
  117. data/spec/omniauth/strategies/oauth2/sound_cloud_spec.rb +5 -0
  118. data/spec/omniauth/strategies/oauth2/taobao_spec.rb +5 -0
  119. data/spec/omniauth/strategies/{teambox_spec.rb → oauth2/teambox_spec.rb} +1 -1
  120. data/spec/omniauth/strategies/{thirty_seven_signals_spec.rb → oauth2/thirty_seven_signals_spec.rb} +1 -1
  121. data/spec/omniauth/strategies/oauth2/viadeo_spec.rb +5 -0
  122. data/spec/omniauth/strategies/{vkontakte_spec.rb → oauth2/vkontakte_spec.rb} +1 -1
  123. data/spec/omniauth/strategies/oauth2/we_pay_spec.rb +5 -0
  124. data/spec/spec_helper.rb +4 -0
  125. metadata +277 -151
  126. data/lib/omniauth/strategies/bitly.rb +0 -46
  127. data/lib/omniauth/strategies/gowalla.rb +0 -72
  128. data/lib/omniauth/strategies/hyves.rb +0 -67
  129. data/lib/omniauth/strategies/mailru.rb +0 -107
  130. data/lib/omniauth/strategies/plurk.rb +0 -58
  131. data/lib/omniauth/strategies/rdio.rb +0 -45
  132. data/lib/omniauth/strategies/salesforce.rb +0 -44
  133. data/lib/omniauth/strategies/smug_mug.rb +0 -42
  134. data/lib/omniauth/strategies/sound_cloud.rb +0 -46
  135. data/lib/omniauth/strategies/tqq.rb +0 -64
  136. data/lib/omniauth/strategies/trade_me.rb +0 -45
  137. data/lib/omniauth/strategies/trip_it.rb +0 -22
  138. data/lib/omniauth/strategies/vkontakte.rb +0 -87
  139. data/spec/omniauth/strategies/oauth2_spec.rb +0 -0
  140. data/spec/omniauth/strategies/oauth_spec.rb +0 -77
  141. data/spec/omniauth/strategies/sound_cloud_spec.rb +0 -5
  142. data/spec/omniauth/strategies/taobao_spec.rb +0 -5
  143. data/spec/omniauth/strategies/twitter_spec.rb +0 -20
data/Gemfile CHANGED
@@ -1,5 +1,9 @@
1
+ require File.expand_path('../lib/omniauth/version', __FILE__)
2
+
1
3
  source 'http://rubygems.org'
2
4
 
5
+ gem 'oa-core', OmniAuth::Version::STRING, :path => '../oa-core'
6
+
3
7
  platforms :jruby do
4
8
  gem 'jruby-openssl', '~> 0.7'
5
9
  end
@@ -3,54 +3,72 @@ require 'omniauth/core'
3
3
  module OmniAuth
4
4
  module Strategies
5
5
  autoload :OAuth, 'omniauth/strategies/oauth'
6
+ autoload :Blogger, 'omniauth/strategies/oauth/blogger'
7
+ autoload :Dopplr, 'omniauth/strategies/oauth/dopplr'
8
+ autoload :Douban, 'omniauth/strategies/oauth/douban'
9
+ autoload :Dropbox, 'omniauth/strategies/oauth/dropbox'
10
+ autoload :Evernote, 'omniauth/strategies/oauth/evernote'
11
+ autoload :Flattr, 'omniauth/strategies/oauth/flattr'
12
+ autoload :Flickr, 'omniauth/strategies/oauth/flickr'
13
+ autoload :Goodreads, 'omniauth/strategies/oauth/goodreads'
14
+ autoload :Google, 'omniauth/strategies/oauth/google'
15
+ autoload :GoogleHealth, 'omniauth/strategies/oauth/google_health'
16
+ autoload :GoogleHealthSandbox,'omniauth/strategies/oauth/google_health_sandbox'
17
+ autoload :Hyves, 'omniauth/strategies/oauth/hyves'
18
+ autoload :Identica, 'omniauth/strategies/oauth/identica'
19
+ autoload :LinkedIn, 'omniauth/strategies/oauth/linked_in'
20
+ autoload :Meetup, 'omniauth/strategies/oauth/meetup'
21
+ autoload :Miso, 'omniauth/strategies/oauth/miso'
22
+ autoload :Netflix, 'omniauth/strategies/oauth/netflix'
23
+ autoload :Orkut, 'omniauth/strategies/oauth/orkut'
24
+ autoload :Qzone, 'omniauth/strategies/oauth/qzone'
25
+ autoload :Plurk, 'omniauth/strategies/oauth/plurk'
26
+ autoload :Rdio, 'omniauth/strategies/oauth/rdio'
27
+ autoload :SmugMug, 'omniauth/strategies/oauth/smug_mug'
28
+ autoload :T163, 'omniauth/strategies/oauth/t163'
29
+ autoload :Tqq, 'omniauth/strategies/oauth/tqq'
30
+ autoload :TradeMe, 'omniauth/strategies/oauth/trade_me'
31
+ autoload :TripIt, 'omniauth/strategies/oauth/trip_it'
32
+ autoload :Tsina, 'omniauth/strategies/oauth/tsina'
33
+ autoload :Tsohu, 'omniauth/strategies/oauth/tsohu'
34
+ autoload :Tumblr, 'omniauth/strategies/oauth/tumblr'
35
+ autoload :Twitter, 'omniauth/strategies/oauth/twitter'
36
+ autoload :TypePad, 'omniauth/strategies/oauth/type_pad'
37
+ autoload :Vimeo, 'omniauth/strategies/oauth/vimeo'
38
+ autoload :Yahoo, 'omniauth/strategies/oauth/yahoo'
39
+ autoload :Yammer, 'omniauth/strategies/oauth/yammer'
40
+ autoload :YouTube, 'omniauth/strategies/oauth/you_tube'
41
+
6
42
  autoload :OAuth2, 'omniauth/strategies/oauth2'
7
- autoload :XAuth, 'omniauth/strategies/xauth'
43
+ autoload :AngelList, 'omniauth/strategies/oauth2/angellist'
44
+ autoload :Bitly, 'omniauth/strategies/oauth2/bitly'
45
+ autoload :Cobot, 'omniauth/strategies/oauth2/cobot'
46
+ autoload :Dailymile, 'omniauth/strategies/oauth2/dailymile'
47
+ autoload :Doit, 'omniauth/strategies/oauth2/doit'
48
+ autoload :Facebook, 'omniauth/strategies/oauth2/facebook'
49
+ autoload :Foursquare, 'omniauth/strategies/oauth2/foursquare'
50
+ autoload :GitHub, 'omniauth/strategies/oauth2/github'
51
+ autoload :Glitch, 'omniauth/strategies/oauth2/glitch'
52
+ autoload :GoogleOAuth2, 'omniauth/strategies/google_oauth2'
53
+ autoload :Gowalla, 'omniauth/strategies/oauth2/gowalla'
54
+ autoload :Instagram, 'omniauth/strategies/oauth2/instagram'
55
+ autoload :Liveid, 'omniauth/strategies/oauth2/liveid'
56
+ autoload :Mailchimp, 'omniauth/strategies/oauth2/mailchimp'
57
+ autoload :Mailru, 'omniauth/strategies/oauth2/mailru'
58
+ autoload :Mixi, 'omniauth/strategies/oauth2/mixi'
59
+ autoload :Renren, 'omniauth/strategies/oauth2/renren'
60
+ autoload :Salesforce, 'omniauth/strategies/oauth2/salesforce'
61
+ autoload :SoundCloud, 'omniauth/strategies/oauth2/sound_cloud'
62
+ autoload :Taobao, 'omniauth/strategies/oauth2/taobao'
63
+ autoload :Teambox, 'omniauth/strategies/oauth2/teambox'
64
+ autoload :ThirtySevenSignals, 'omniauth/strategies/oauth2/thirty_seven_signals'
65
+ autoload :Viadeo, 'omniauth/strategies/oauth2/viadeo'
66
+ autoload :Vkontakte, 'omniauth/strategies/oauth2/vkontakte'
67
+ autoload :WePay, 'omniauth/strategies/oauth2/we_pay'
8
68
 
9
- autoload :Bitly, 'omniauth/strategies/bitly'
10
- autoload :Dailymile, 'omniauth/strategies/dailymile'
11
- autoload :Doit, 'omniauth/strategies/doit'
12
- autoload :Dopplr, 'omniauth/strategies/dopplr'
13
- autoload :Douban, 'omniauth/strategies/douban'
14
- autoload :Evernote, 'omniauth/strategies/evernote'
15
- autoload :Facebook, 'omniauth/strategies/facebook'
16
- autoload :Foursquare, 'omniauth/strategies/foursquare'
17
- autoload :GitHub, 'omniauth/strategies/github'
18
- autoload :Goodreads, 'omniauth/strategies/goodreads'
19
- autoload :Google, 'omniauth/strategies/google'
20
- autoload :Gowalla, 'omniauth/strategies/gowalla'
21
- autoload :Hyves, 'omniauth/strategies/hyves'
22
- autoload :Identica, 'omniauth/strategies/identica'
23
- autoload :Instagram, 'omniauth/strategies/instagram'
24
- autoload :Instapaper, 'omniauth/strategies/instapaper'
25
- autoload :LinkedIn, 'omniauth/strategies/linked_in'
26
- autoload :Meetup, 'omniauth/strategies/meetup'
27
- autoload :Miso, 'omniauth/strategies/miso'
28
- autoload :Mixi, 'omniauth/strategies/mixi'
29
- autoload :Netflix, 'omniauth/strategies/netflix'
30
- autoload :Qzone, 'omniauth/strategies/qzone'
31
- autoload :Plurk, 'omniauth/strategies/plurk'
32
- autoload :Rdio, 'omniauth/strategies/rdio'
33
- autoload :Renren, 'omniauth/strategies/renren'
34
- autoload :Salesforce, 'omniauth/strategies/salesforce'
35
- autoload :SmugMug, 'omniauth/strategies/smug_mug'
36
- autoload :SoundCloud, 'omniauth/strategies/sound_cloud'
37
- autoload :T163, 'omniauth/strategies/t163'
38
- autoload :TB, 'omniauth/strategies/taobao'
39
- autoload :Teambox, 'omniauth/strategies/teambox'
40
- autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
41
- autoload :Tqq, 'omniauth/strategies/tqq'
42
- autoload :TradeMe, 'omniauth/strategies/trade_me'
43
- autoload :TripIt, 'omniauth/strategies/trip_it'
44
- autoload :Tsina, 'omniauth/strategies/tsina'
45
- autoload :Tsohu, 'omniauth/strategies/tsohu'
46
- autoload :Tumblr, 'omniauth/strategies/tumblr'
47
- autoload :Twitter, 'omniauth/strategies/twitter'
48
- autoload :TypePad, 'omniauth/strategies/type_pad'
49
- autoload :Vimeo, 'omniauth/strategies/vimeo'
50
- autoload :Vkontakte, 'omniauth/strategies/vkontakte'
51
- autoload :Yahoo, 'omniauth/strategies/yahoo'
52
- autoload :Yammer, 'omniauth/strategies/yammer'
53
- autoload :YouTube, 'omniauth/strategies/you_tube'
54
- autoload :Mailru, 'omniauth/strategies/mailru'
69
+
70
+ autoload :XAuth, 'omniauth/strategies/xauth'
71
+ autoload :Instapaper, 'omniauth/strategies/xauth/instapaper'
72
+
55
73
  end
56
74
  end
@@ -0,0 +1,59 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ # OAuth 2.0 based authentication with Google.
7
+ class GoogleOAuth2 < OAuth2
8
+ # @param [Rack Application] app standard middleware application argument
9
+ # @param [String] client_id the application ID for your client
10
+ # @param [String] client_secret the application secret
11
+ # @option options [String] :scope ('https://www.googleapis.com/auth/userinfo.email') space-separated services that you need.
12
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
13
+ client_options = {
14
+ :site => 'https://accounts.google.com',
15
+ :authorize_url => '/o/oauth2/auth',
16
+ :token_url => '/o/oauth2/token'
17
+ }
18
+
19
+ super(app, :google_oauth2, client_id, client_secret, client_options, options, &block)
20
+ end
21
+
22
+ def request_phase
23
+ google_email_scope = "www.googleapis.com/auth/userinfo.email"
24
+ options[:scope] ||= "https://#{google_email_scope}"
25
+ options[:scope] << "https://#{google_email_scope}" unless options[:scope] =~ %r[http[s]?:\/\/#{google_email_scope}]
26
+ redirect client.auth_code.authorize_url(
27
+ {:redirect_uri => callback_url, :response_type => "code"}.merge(options))
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => user_info['uid'],
33
+ 'user_info' => user_info,
34
+ 'credentials' => {'expires_at' => @access_token.expires_at},
35
+ 'extra' => {'user_hash' => user_data}
36
+ })
37
+ end
38
+
39
+ def user_info
40
+ if user_data['data']['isVerified']
41
+ email = user_data['data']['email']
42
+ else
43
+ email = nil
44
+ end
45
+ {
46
+ 'email' => email,
47
+ 'uid' => email,
48
+ 'name' => email
49
+ }
50
+ end
51
+
52
+ def user_data
53
+ @data ||=
54
+ @access_token.get("https://www.googleapis.com/userinfo/email?alt=json").parsed
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -7,7 +7,7 @@ module OmniAuth
7
7
  class OAuth
8
8
  include OmniAuth::Strategy
9
9
 
10
- def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
10
+ def initialize(app, name, consumer_key=nil, consumer_secret=nil, consumer_options={}, options={}, &block)
11
11
  self.consumer_key = consumer_key
12
12
  self.consumer_secret = consumer_secret
13
13
  self.consumer_options = consumer_options
@@ -40,9 +40,13 @@ module OmniAuth
40
40
 
41
41
  rescue ::Timeout::Error => e
42
42
  fail!(:timeout, e)
43
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
44
+ fail!(:service_unavailable, e)
43
45
  end
44
46
 
45
47
  def callback_phase
48
+ raise OmniAuth::NoSessionError.new("Session Expired") if session['oauth'].nil?
49
+
46
50
  request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
47
51
 
48
52
  opts = {}
@@ -56,12 +60,14 @@ module OmniAuth
56
60
  super
57
61
  rescue ::Timeout::Error => e
58
62
  fail!(:timeout, e)
59
- rescue ::Net::HTTPFatalError => e
63
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
60
64
  fail!(:service_unavailable, e)
61
65
  rescue ::OAuth::Unauthorized => e
62
66
  fail!(:invalid_credentials, e)
63
67
  rescue ::NoMethodError, ::MultiJson::DecodeError => e
64
68
  fail!(:invalid_response, e)
69
+ rescue ::OmniAuth::NoSessionError => e
70
+ fail!(:session_expired, e)
65
71
  end
66
72
 
67
73
  def auth_hash
@@ -0,0 +1,58 @@
1
+ # Based heavily on the Google strategy, monkeypatch and all
2
+ require 'omniauth/oauth'
3
+ require 'multi_json'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ # Authenticate to YouTube via OAuth and retrieve basic user info.
8
+ #
9
+ # Usage:
10
+ # use OmniAuth::Strategies::YouTube, 'consumerkey', 'consumersecret'
11
+ class Blogger < 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, :blogger, consumer_key, consumer_secret, client_options, options, &block)
20
+ end
21
+
22
+ def auth_hash
23
+ ui = user_info
24
+ OmniAuth::Utils.deep_merge(super, {
25
+ 'uid' => ui['uid'],
26
+ 'user_info' => ui,
27
+ 'extra' => {'user_hash' => user_hash},
28
+ })
29
+ end
30
+
31
+ # TODO: Remove contact list from hash returned to the application
32
+ def user_info
33
+ {
34
+ 'uid' => user_hash['feed']['author'][0]['email']['$t'],
35
+ 'nickname' => user_hash['feed']['author'][0]['name']['$t'],
36
+ }
37
+ end
38
+
39
+ def user_hash
40
+ # Using Contact feed
41
+ @user_hash ||= MultiJson.decode(@access_token.get('https://www.google.com/m8/feeds/contacts/default/full/?alt=json').body)
42
+ end
43
+
44
+ def request_phase
45
+ request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://www.blogger.com/feeds/ http://www.google.com/m8/feeds/'})
46
+ session['oauth'] ||= {}
47
+ session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
48
+ r = Rack::Response.new
49
+ if request_token.callback_confirmed?
50
+ r.redirect(request_token.authorize_url)
51
+ else
52
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
53
+ end
54
+ r.finish
55
+ end
56
+ end
57
+ end
58
+ end
@@ -3,25 +3,21 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- #
7
6
  # Authenticate to Dopplr via OAuth and retrieve an access token for API usage
8
7
  #
9
8
  # Usage:
10
- #
11
9
  # use OmniAuth::Strategies::Dopplr, 'consumerkey', 'consumersecret'
12
- #
13
10
  class Dopplr < OmniAuth::Strategies::OAuth
14
11
  # Initialize the Dopplr strategy.
15
12
  #
16
13
  # @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)
14
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
18
15
  client_options = {
16
+ :access_token_path => '/oauth/access_token',
17
+ :authorize_path => '/oauth/authorize',
18
+ :request_token_path => '/oauth/request_token',
19
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
20
  }
24
-
25
21
  super(app, :dopplr, consumer_key, consumer_secret, client_options, options, &block)
26
22
  end
27
23
 
@@ -29,25 +25,27 @@ module OmniAuth
29
25
  @data ||= MultiJson.decode(@access_token.get('/oauthapi/whoami').body)['whoami']
30
26
  end
31
27
 
28
+ def auth_hash
29
+ OmniAuth::Utils.deep_merge(
30
+ super, {
31
+ 'uid' => user_data['nick'],
32
+ 'user_info' => user_info,
33
+ }
34
+ )
35
+ end
36
+
32
37
  def user_info
33
38
  {
34
- 'nickname' => user_data["nick"],
35
- 'first_name' => user_data["forename"],
36
- 'last_name' => user_data["surname"],
39
+ 'nickname' => user_data['nick'],
40
+ 'first_name' => user_data['forename'],
41
+ 'last_name' => user_data['surname'],
37
42
  'name' => "#{user_data['forename']} #{user_data['surname']}",
38
43
  'urls' => {
39
- 'Dopplr' => user_data["dopplr_url"],
40
- 'DopplrMobile' => user_data["mobile_url"],
41
- }
44
+ 'Dopplr' => user_data['dopplr_url'],
45
+ 'DopplrMobile' => user_data['mobile_url'],
46
+ },
42
47
  }
43
48
  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
49
  end
52
50
  end
53
51
  end
@@ -6,40 +6,40 @@ module OmniAuth
6
6
  #
7
7
  # Authenticate to Douban via OAuth and retrieve basic
8
8
  # user information.
9
- #
10
9
  # Usage:
11
- #
12
10
  # use OmniAuth::Strategies::Douban, 'APIKey', 'APIKeySecret'
13
- #
14
11
  class Douban < OmniAuth::Strategies::OAuth
15
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
12
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
16
13
  # Although in OAuth spec the :realm parameter is optional,
17
14
  # it is required for Douban.
18
15
  client_options = {
19
- :site => 'http://www.douban.com',
16
+ :access_token_path => '/service/auth/access_token',
17
+ :authorize_path => '/service/auth/authorize',
18
+ :realm => 'OmniAuth',
20
19
  :request_token_path => '/service/auth/request_token',
21
- :access_token_path => '/service/auth/access_token',
22
- :authorize_path => '/service/auth/authorize',
23
- :realm => 'OmniAuth'
20
+ :site => 'http://www.douban.com',
24
21
  }
25
22
 
26
23
  super(app, :douban, consumer_key, consumer_secret, client_options, options, &block)
27
24
  end
28
25
 
29
26
  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
- })
27
+ OmniAuth::Utils.deep_merge(
28
+ super, {
29
+ 'uid' => @access_token.params[:douban_user_id],
30
+ 'user_info' => user_info,
31
+ 'extra' => {
32
+ 'user_hash' => user_hash,
33
+ },
34
+ }
35
+ )
35
36
  end
36
37
 
37
38
  def user_info
38
39
  user_hash = self.user_hash
39
-
40
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']
41
+ image = user_hash['link'].find{|l| l['@rel'] == 'icon'}['@href']
42
+ douban_url = user_hash['link'].find{|l| l['@rel'] == 'alternate'}['@href']
43
43
  {
44
44
  'username' => user_hash['db:uid']['$t'],
45
45
  'name' => user_hash['title']['$t'],
@@ -47,8 +47,8 @@ module OmniAuth
47
47
  'image' => image,
48
48
  'description' => user_hash['content']['$t'],
49
49
  'urls' => {
50
- 'Douban' => douban_url
51
- }
50
+ 'Douban' => douban_url,
51
+ },
52
52
  }
53
53
  end
54
54
 
@@ -0,0 +1,40 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Dropbox < OmniAuth::Strategies::OAuth
7
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
8
+ client_options = {
9
+ :authorize_url => 'https://www.dropbox.com/0/oauth/authorize',
10
+ :access_token_url => 'https://api.dropbox.com/0/oauth/access_token',
11
+ :proxy => ENV['HTTP_PROXY'] || ENV['http_proxy'],
12
+ :request_token_url => 'https://api.dropbox.com/0/oauth/request_token',
13
+ :site => 'https://api.dropbox.com',
14
+ }
15
+ super(app, :dropbox, consumer_key, consumer_secret, client_options, options, &block)
16
+ end
17
+
18
+ def auth_hash
19
+ OmniAuth::Utils.deep_merge(
20
+ super, {
21
+ 'uid' => user_data['uid'],
22
+ 'user_info' => user_info,
23
+ }
24
+ )
25
+ end
26
+
27
+ def user_data
28
+ @data ||= MultiJson.decode(@access_token.get('/0/account/info').body)
29
+ end
30
+
31
+ def user_info
32
+ {
33
+ 'name' => user_data['display_name'],
34
+ 'uid' => user_data['uid'],
35
+ 'email' => user_data['email']
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end