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
@@ -3,41 +3,45 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- #
7
6
  # Authenticate to Identica via OAuth and retrieve basic
8
7
  # user information.
9
8
  #
10
9
  # Usage:
11
- #
12
10
  # use OmniAuth::Strategies::Identica, 'consumerkey', 'consumersecret'
13
- #
14
11
  class Identica < OmniAuth::Strategies::OAuth
15
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
- super(app, :identica, consumer_key, consumer_secret,
17
- {:site => 'http://identi.ca',
18
- :request_token_path => "/api/oauth/request_token",
19
- :access_token_path => "/api/oauth/access_token",
20
- :authorize_path => "/api/oauth/authorize"}, options, &block)
12
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
13
+ client_options = {
14
+ :access_token_path => '/api/oauth/access_token',
15
+ :authorize_path => '/api/oauth/authorize',
16
+ :request_token_path => '/api/oauth/request_token',
17
+ :site => 'http://identi.ca',
18
+ }
19
+ super(app, :identica, consumer_key, consumer_secret, client_options, options, &block)
21
20
  end
22
21
 
23
22
  def auth_hash
24
- OmniAuth::Utils.deep_merge(super, {
25
- 'uid' => user_hash['id'],
26
- 'user_info' => user_info,
27
- 'extra' => {'user_hash' => user_hash}
28
- })
23
+ OmniAuth::Utils.deep_merge(
24
+ super, {
25
+ 'uid' => user_hash['id'],
26
+ 'user_info' => user_info,
27
+ 'extra' => {
28
+ 'user_hash' => user_hash,
29
+ },
30
+ }
31
+ )
29
32
  end
30
33
 
31
34
  def user_info
32
35
  user_hash = self.user_hash
33
-
34
36
  {
35
37
  'nickname' => user_hash['screen_name'],
36
38
  'name' => user_hash['name'],
37
39
  'location' => user_hash['location'],
38
40
  'image' => user_hash['profile_image_url'],
39
41
  'description' => user_hash['description'],
40
- 'urls' => {'Website' => user_hash['url']}
42
+ 'urls' => {
43
+ 'Website' => user_hash['url'],
44
+ },
41
45
  }
42
46
  end
43
47
 
@@ -4,27 +4,27 @@ require 'omniauth/oauth'
4
4
  module OmniAuth
5
5
  module Strategies
6
6
  class LinkedIn < OmniAuth::Strategies::OAuth
7
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
7
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
8
8
  client_options = {
9
- :site => 'https://api.linkedin.com',
10
- :request_token_path => '/uas/oauth/requestToken',
11
9
  :access_token_path => '/uas/oauth/accessToken',
12
10
  :authorize_path => '/uas/oauth/authorize',
13
- :scheme => :header
11
+ :request_token_path => '/uas/oauth/requestToken',
12
+ :scheme => :header,
13
+ :site => 'https://api.linkedin.com',
14
14
  }
15
-
16
15
  client_options[:authorize_path] = '/uas/oauth/authenticate' unless options[:sign_in] == false
17
-
18
16
  super(app, :linked_in, consumer_key, consumer_secret, client_options, options, &block)
19
17
  end
20
18
 
21
19
  def auth_hash
22
20
  hash = user_hash(@access_token)
23
21
 
24
- OmniAuth::Utils.deep_merge(super, {
25
- 'uid' => hash.delete('id'),
26
- 'user_info' => hash
27
- })
22
+ OmniAuth::Utils.deep_merge(super,
23
+ {
24
+ 'uid' => hash.delete('id'),
25
+ 'user_info' => hash,
26
+ }
27
+ )
28
28
  end
29
29
 
30
30
  def user_hash(access_token)
@@ -34,17 +34,17 @@ module OmniAuth
34
34
  'id' => person['id'],
35
35
  'first_name' => person['first_name'],
36
36
  'last_name' => person['last_name'],
37
- 'nickname' => person['public_profile_url'].split('/').last,
37
+ 'nickname' => person['public_profile_url'].to_s.split('/').last,
38
38
  'location' => person['location']['name'],
39
39
  'image' => person['picture_url'],
40
40
  'description' => person['headline'],
41
- 'public_profile_url' => person['public_profile_url']
41
+ 'public_profile_url' => person['public_profile_url'],
42
42
  }
43
- hash['urls']={}
43
+ hash['urls'] = {}
44
44
  member_urls = person['member_url_resources']['member_url']
45
45
  if (!member_urls.nil?) and (!member_urls.empty?)
46
46
  [member_urls].flatten.each do |url|
47
- hash['urls']["#{url['name']}"]=url['url']
47
+ hash['urls']["#{url['name']}"] = url['url']
48
48
  end
49
49
  end
50
50
  hash['urls']['LinkedIn'] = person['public_profile_url']
@@ -3,34 +3,36 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- #
7
6
  # Authenticate with Meetup via OAuth and retrieve an access token for API usage
8
7
  #
9
8
  # Usage:
10
- #
11
9
  # use OmniAuth::Strategies::Meetup, 'consumerkey', 'consumersecret'
12
- #
13
10
  class Meetup < OmniAuth::Strategies::OAuth
14
11
  # Initialize meetup middleware
15
12
  # @param [Rack Application] app standard middleware application parameter
16
13
  # @param [String] consumer_key the application consumer id
17
14
  # @param [String] consumer_secret the application consumer secret
18
15
  # @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
19
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
20
17
  auth_path = (options[:sign_in] == false) ? 'http://www.meetup.com/authorize' : 'http://www.meetup.com/authenticate'
21
-
22
- super(app, :meetup, consumer_key, consumer_secret,
23
- { :request_token_path => "https://api.meetup.com/oauth/request",
24
- :access_token_path => "https://api.meetup.com/oauth/access",
25
- :authorize_path => auth_path }, options)
18
+ client_options = {
19
+ :access_token_path => 'https://api.meetup.com/oauth/access',
20
+ :authorize_path => auth_path,
21
+ :request_token_path => 'https://api.meetup.com/oauth/request',
22
+ }
23
+ super(app, :meetup, consumer_key, consumer_secret, client_options, options, &block)
26
24
  end
27
25
 
28
26
  def auth_hash
29
- OmniAuth::Utils.deep_merge(super, {
30
- 'uid' => member['id'],
31
- 'user_info' => user_info,
32
- 'extra' => { 'user_hash' => member }
33
- })
27
+ OmniAuth::Utils.deep_merge(super,
28
+ {
29
+ 'uid' => member['id'],
30
+ 'user_info' => user_info,
31
+ 'extra' => {
32
+ 'user_hash' => member,
33
+ },
34
+ }
35
+ )
34
36
  end
35
37
 
36
38
  def user_info
@@ -39,8 +41,8 @@ module OmniAuth
39
41
  'image' => member['photo_url'],
40
42
  'location' => member['city'],
41
43
  'urls' => {
42
- 'profile' => member['link']
43
- }
44
+ 'profile' => member['link'],
45
+ },
44
46
  }
45
47
  end
46
48
 
@@ -12,16 +12,23 @@ module OmniAuth
12
12
  # use OmniAuth::Strategies::Miso, 'consumerkey', 'consumersecret'
13
13
  #
14
14
  class Miso < OmniAuth::Strategies::OAuth
15
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
- super(app, :miso, consumer_key, consumer_secret, {:site => 'https://gomiso.com'}, options)
15
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
16
+ client_options = {
17
+ :site => 'https://gomiso.com',
18
+ }
19
+ super(app, :miso, consumer_key, consumer_secret, client_options, options, &block)
17
20
  end
18
21
 
19
22
  def auth_hash
20
- OmniAuth::Utils.deep_merge(super, {
21
- 'uid' => user_hash['id'],
22
- 'user_info' => user_info,
23
- 'extra' => {'user_hash' => user_hash}
24
- })
23
+ OmniAuth::Utils.deep_merge(super,
24
+ {
25
+ 'uid' => user_hash['id'],
26
+ 'user_info' => user_info,
27
+ 'extra' => {
28
+ 'user_hash' => user_hash,
29
+ },
30
+ }
31
+ )
25
32
  end
26
33
 
27
34
  def user_info
@@ -9,14 +9,14 @@ module OmniAuth
9
9
  # use OmniAuth::Strategies::Netflix, 'consumerkey', 'consumersecret'
10
10
  #
11
11
  class Netflix < OmniAuth::Strategies::OAuth
12
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
13
- opts = {
14
- :site => 'http://api.netflix.com',
15
- :request_token_path => "/oauth/request_token",
16
- :access_token_path => "/oauth/access_token",
17
- :authorize_url => "https://api-user.netflix.com/oauth/login"
12
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
13
+ client_options = {
14
+ :access_token_path => '/oauth/access_token',
15
+ :authorize_url => 'https://api-user.netflix.com/oauth/login',
16
+ :request_token_path => '/oauth/request_token',
17
+ :site => 'http://api.netflix.com',
18
18
  }
19
- super(app, :netflix, consumer_key, consumer_secret, opts, options, &block)
19
+ super(app, :netflix, consumer_key, consumer_secret, client_options, options, &block)
20
20
  end
21
21
 
22
22
  def request_phase
@@ -24,7 +24,6 @@ module OmniAuth
24
24
  session['oauth'] ||= {}
25
25
  session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
26
26
  r = Rack::Response.new
27
-
28
27
  if request_token.callback_confirmed?
29
28
  r.redirect(request_token.authorize_url(
30
29
  :oauth_consumer_key => consumer.key
@@ -35,16 +34,19 @@ module OmniAuth
35
34
  :oauth_consumer_key => consumer.key
36
35
  ))
37
36
  end
38
-
39
37
  r.finish
40
38
  end
41
39
 
42
40
  def auth_hash
43
- OmniAuth::Utils.deep_merge(super, {
44
- 'uid' => user_hash['user']['user_id'],
45
- 'user_info' => user_info,
46
- 'extra' => { 'user_hash' => user_hash['user'] }
47
- })
41
+ OmniAuth::Utils.deep_merge(super,
42
+ {
43
+ 'uid' => user_hash['user']['user_id'],
44
+ 'user_info' => user_info,
45
+ 'extra' => {
46
+ 'user_hash' => user_hash['user'],
47
+ },
48
+ }
49
+ )
48
50
  end
49
51
 
50
52
  def user_info
@@ -0,0 +1,63 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Orkut via OAuth and retrieve basic user info.
8
+ #
9
+ # Usage:
10
+ #
11
+ # use OmniAuth::Strategies::Orkut, 'consumerkey', 'consumersecret'
12
+ #
13
+ class Orkut < OmniAuth::Strategies::OAuth
14
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
15
+ client_options = {
16
+ :site => 'https://www.google.com',
17
+ :request_token_path => '/accounts/OAuthGetRequestToken',
18
+ :access_token_path => '/accounts/OAuthGetAccessToken',
19
+ :authorize_path => '/accounts/OAuthAuthorizeToken'
20
+ }
21
+ super(app, :orkut, consumer_key, consumer_secret, client_options, options)
22
+ end
23
+
24
+ def auth_hash
25
+ ui = user_info
26
+ OmniAuth::Utils.deep_merge(super, {
27
+ 'uid' => ui['uid'],
28
+ 'user_info' => ui,
29
+ 'extra' => {'user_hash' => user_hash}
30
+ })
31
+ end
32
+
33
+ def user_info
34
+ entry = user_hash['entry']
35
+ {
36
+ 'uid' => entry['id'],
37
+ 'first_name' => entry['name']['givenName'],
38
+ 'last_name' => entry['name']['familyName'],
39
+ 'image' => entry['thumbnailUrl']
40
+ }
41
+ end
42
+
43
+ def user_hash
44
+ @user_hash ||= MultiJson.decode(@access_token.get("http://www.orkut.com/social/rest/people/@me/@self").body)
45
+ end
46
+
47
+ def request_phase
48
+ request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://orkut.gmodules.com/social/rest'})
49
+ session['oauth'] ||= {}
50
+ session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
51
+ r = Rack::Response.new
52
+
53
+ if request_token.callback_confirmed?
54
+ r.redirect(request_token.authorize_url)
55
+ else
56
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
57
+ end
58
+
59
+ r.finish
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,57 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ # Authenticate to Plurk via OAuth and retrieve basic user info.
7
+ #
8
+ # Please note that this strategy relies on Plurk API 2.0,
9
+ # which is still in Beta.
10
+ #
11
+ # Usage:
12
+ # use OmniAuth::Strategies::Plurk
13
+ class Plurk < OmniAuth::Strategies::OAuth
14
+ # @param [Rack Application] app standard middleware application parameter
15
+ # @param [String] consumer_key App key [registered on plurk] (http://www.plurk.com/PlurkApp/register)
16
+ # @param [String] consumer_secret App secret registered on plurk
17
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
18
+ client_options = {
19
+ :access_token_path => '/OAuth/access_token',
20
+ :authorize_path => '/OAuth/authorize',
21
+ :request_token_path => '/OAuth/request_token',
22
+ :site => 'http://www.plurk.com',
23
+ }
24
+ super(app, :plurk, consumer_key, consumer_secret, client_options, options, &block)
25
+ end
26
+
27
+ def auth_hash
28
+ user = self.user_hash
29
+ OmniAuth::Utils.deep_merge(super,
30
+ {
31
+ 'uid' => user['id'],
32
+ 'user_info' => user_info,
33
+ 'extra' => {
34
+ 'user_hash' => user_hash,
35
+ },
36
+ }
37
+ )
38
+ end
39
+
40
+ def user_info
41
+ user = self.user_hash
42
+ {
43
+ 'name' => user['full_name'],
44
+ 'nickname' => user['display_name'] || user['nick_name'],
45
+ 'location' => user['location'],
46
+ 'image' => user['has_profile_image'] == 1 ? "http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif" : 'http://www.plurk.com/static/default_medium.gif',
47
+ 'urls' => {'Plurk' => 'http://plurk.com/' + user['nick_name']},
48
+ }
49
+ end
50
+
51
+ def user_hash
52
+ @user_hash ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info']
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -13,18 +13,17 @@ module OmniAuth
13
13
  #
14
14
  class Qzone < OmniAuth::Strategies::OAuth
15
15
  # Initialize the middleware
16
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
17
17
  client_options = {
18
- :site => 'http://openapi.qzone.qq.com',
18
+ :access_token_path => '/oauth/qzoneoauth_access_token',
19
+ :authorize_path => '/oauth/qzoneoauth_authorize',
20
+ :http_method => :get,
19
21
  :request_token_path => '/oauth/qzoneoauth_request_token',
20
- :access_token_path => '/oauth/qzoneoauth_access_token',
21
- :authorize_path => '/oauth/qzoneoauth_authorize',
22
- :scheme => :query_string,
23
- :http_method => :get
22
+ :scheme => :query_string,
23
+ :site => 'http://openapi.qzone.qq.com',
24
24
  }
25
-
26
25
  options[:authorize_params] = {:oauth_consumer_key => consumer_key}
27
- super(app, :qzone, consumer_key, consumer_secret, client_options, options)
26
+ super(app, :qzone, consumer_key, consumer_secret, client_options, options, &block)
28
27
  end
29
28
 
30
29
  #HACK qzone is using a none-standard parameter oauth_overicode
@@ -40,11 +39,15 @@ module OmniAuth
40
39
 
41
40
  def auth_hash
42
41
  ui = user_info
43
- OmniAuth::Utils.deep_merge(super, {
42
+ OmniAuth::Utils.deep_merge(super,
43
+ {
44
44
  'uid' => ui['uid'],
45
45
  'user_info' => ui,
46
- 'extra' => {'user_hash' => user_hash}
47
- })
46
+ 'extra' => {
47
+ 'user_hash' => user_hash,
48
+ },
49
+ }
50
+ )
48
51
  end
49
52
 
50
53
  def user_info
@@ -57,7 +60,7 @@ module OmniAuth
57
60
  'urls' => {
58
61
  'figureurl_1' => user_hash['figureurl_1'],
59
62
  'figureurl_2' => user_hash['figureurl_2'],
60
- }
63
+ },
61
64
  }
62
65
  end
63
66