oa-oauth 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/lib/omniauth/oauth.rb +33 -24
  2. data/lib/omniauth/strategies/bitly.rb +4 -4
  3. data/lib/omniauth/strategies/doit.rb +8 -8
  4. data/lib/omniauth/strategies/dopplr.rb +6 -6
  5. data/lib/omniauth/strategies/douban.rb +60 -0
  6. data/lib/omniauth/strategies/evernote.rb +1 -6
  7. data/lib/omniauth/strategies/facebook.rb +5 -5
  8. data/lib/omniauth/strategies/foursquare.rb +12 -7
  9. data/lib/omniauth/strategies/github.rb +6 -6
  10. data/lib/omniauth/strategies/goodreads.rb +3 -3
  11. data/lib/omniauth/strategies/gowalla.rb +6 -6
  12. data/lib/omniauth/strategies/hyves.rb +14 -14
  13. data/lib/omniauth/strategies/instagram.rb +7 -7
  14. data/lib/omniauth/strategies/instapaper.rb +6 -6
  15. data/lib/omniauth/strategies/linked_in.rb +9 -9
  16. data/lib/omniauth/strategies/miso.rb +5 -5
  17. data/lib/omniauth/strategies/mixi.rb +8 -8
  18. data/lib/omniauth/strategies/oauth2.rb +21 -22
  19. data/lib/omniauth/strategies/qzone.rb +69 -0
  20. data/lib/omniauth/strategies/rdio.rb +45 -0
  21. data/lib/omniauth/strategies/renren.rb +87 -0
  22. data/lib/omniauth/strategies/salesforce.rb +1 -1
  23. data/lib/omniauth/strategies/smug_mug.rb +4 -4
  24. data/lib/omniauth/strategies/sound_cloud.rb +7 -7
  25. data/lib/omniauth/strategies/t163.rb +57 -0
  26. data/lib/omniauth/strategies/thirty_seven_signals.rb +5 -5
  27. data/lib/omniauth/strategies/tqq.rb +64 -0
  28. data/lib/omniauth/strategies/trade_me.rb +4 -4
  29. data/lib/omniauth/strategies/tsina.rb +79 -0
  30. data/lib/omniauth/strategies/tsohu.rb +57 -0
  31. data/lib/omniauth/strategies/twitter.rb +7 -7
  32. data/lib/omniauth/strategies/type_pad.rb +6 -6
  33. data/lib/omniauth/strategies/vkontakte.rb +1 -1
  34. data/lib/omniauth/strategies/xauth.rb +9 -9
  35. data/lib/omniauth/strategies/yahoo.rb +4 -4
  36. data/lib/omniauth/strategies/yammer.rb +43 -0
  37. data/lib/omniauth/version.rb +19 -0
  38. data/oa-oauth.gemspec +13 -10
  39. data/spec/omniauth/strategies/bitly_spec.rb +1 -1
  40. data/spec/omniauth/strategies/dailymile_spec.rb +1 -1
  41. data/spec/omniauth/strategies/doit_spec.rb +2 -2
  42. data/spec/omniauth/strategies/dopplr_spec.rb +1 -1
  43. data/spec/omniauth/strategies/douban_spec.rb +5 -0
  44. data/spec/omniauth/strategies/evernote_spec.rb +3 -5
  45. data/spec/omniauth/strategies/facebook_spec.rb +2 -2
  46. data/spec/omniauth/strategies/foursquare_spec.rb +15 -1
  47. data/spec/omniauth/strategies/github_spec.rb +1 -1
  48. data/spec/omniauth/strategies/goodreads_spec.rb +1 -1
  49. data/spec/omniauth/strategies/google_spec.rb +1 -1
  50. data/spec/omniauth/strategies/gowalla_spec.rb +3 -3
  51. data/spec/omniauth/strategies/hyves_spec.rb +2 -2
  52. data/spec/omniauth/strategies/identica_spec.rb +1 -1
  53. data/spec/omniauth/strategies/linked_in_spec.rb +1 -1
  54. data/spec/omniauth/strategies/meetup_spec.rb +1 -1
  55. data/spec/omniauth/strategies/miso_spec.rb +2 -2
  56. data/spec/omniauth/strategies/netflix_spec.rb +1 -1
  57. data/spec/omniauth/strategies/oauth_spec.rb +1 -1
  58. data/spec/omniauth/strategies/rdio_spec.rb +5 -0
  59. data/spec/omniauth/strategies/salesforce_spec.rb +1 -1
  60. data/spec/omniauth/strategies/smug_mug_spec.rb +3 -3
  61. data/spec/omniauth/strategies/sound_cloud_spec.rb +2 -2
  62. data/spec/omniauth/strategies/t163_spec.rb +5 -0
  63. data/spec/omniauth/strategies/teambox_spec.rb +1 -1
  64. data/spec/omniauth/strategies/thirty_seven_signals_spec.rb +2 -2
  65. data/spec/omniauth/strategies/trade_me_spec.rb +2 -2
  66. data/spec/omniauth/strategies/trip_it_spec.rb +1 -1
  67. data/spec/omniauth/strategies/tsina_spec.rb +5 -0
  68. data/spec/omniauth/strategies/tumblr_spec.rb +2 -2
  69. data/spec/omniauth/strategies/twitter_spec.rb +4 -4
  70. data/spec/omniauth/strategies/type_pad_spec.rb +1 -1
  71. data/spec/omniauth/strategies/vimeo_spec.rb +2 -2
  72. data/spec/omniauth/strategies/vkontakte_spec.rb +1 -1
  73. data/spec/omniauth/strategies/yahoo_spec.rb +1 -1
  74. data/spec/omniauth/strategies/yammer_spec.rb +5 -0
  75. data/spec/omniauth/strategies/you_tube_spec.rb +1 -1
  76. data/spec/spec_helper.rb +4 -9
  77. data/spec/support/shared_examples.rb +3 -3
  78. metadata +77 -25
  79. data/Gemfile +0 -3
@@ -0,0 +1,87 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+ require 'digest/md5'
4
+ require 'net/http'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ # Authenticate to Renren utilizing OAuth 2.0 and retrieve
9
+ # basic user information.
10
+ #
11
+ # @example Basic Usage
12
+ # use OmniAuth::Strategies::Renren, 'client_id', 'client_secret'
13
+ class Renren < OAuth2
14
+ # @param [Rack Application] app standard middleware application parameter
15
+ # @param [String] client_id the application id as [registered on Renren](http://dev.renren.com/)
16
+ # @param [String] client_secret the application secret as registered on Renren
17
+ # @option options [String] :scope ('publish_feed,status_update') comma-separated extended permissions such as `publish_feed` and `status_update`
18
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
19
+ client_options = {
20
+ :site => "http://graph.renren.com/",
21
+ :authorize_url => "/oauth/authorize",
22
+ :access_token_url => "/oauth/token"
23
+ }
24
+
25
+ super(app, :renren, client_id, client_secret, client_options, options, &block)
26
+ end
27
+
28
+ def user_data
29
+ @data ||= MultiJson.decode(Net::HTTP.post_form(URI.parse('http://api.renren.com/restserver.do'), signed_params).body)[0]
30
+ end
31
+
32
+ def signed_params
33
+ params = {}
34
+ params[:api_key] = client.id
35
+ params[:method] = "users.getInfo"
36
+ params[:call_id] = Time.now.to_i
37
+ params[:format] = "json"
38
+ params[:v] = "1.0"
39
+ params[:uids] = session_key["user"]["id"]
40
+ params[:session_key] = session_key["renren_token"]["session_key"]
41
+ params[:sig] = Digest::MD5.hexdigest(params.map {|k,v| "#{k}=#{v}"}.sort.join("") + client.secret)
42
+ params
43
+ end
44
+
45
+ def session_key
46
+ @session_key ||= MultiJson.decode(@access_token.get('/renren_api/session_key'))
47
+ end
48
+
49
+ def request_phase
50
+ options[:scope] ||= "publish_feed"
51
+ super
52
+ end
53
+
54
+ def build_access_token
55
+ if renren_session.nil? || renrensession.empty?
56
+ super
57
+ else
58
+ @access_token = ::OAuth2::AccessToken.new(client, renren_session['access_token'])
59
+ end
60
+ end
61
+
62
+ def renren_session
63
+ session_cookie = request.cookies["rrs_#{client.id}"]
64
+ if session_cookie
65
+ @renren_session ||= Rack::Utils.parse_query(request.cookies["rrs_#{client.id}"].gsub('"', ''))
66
+ else
67
+ nil
68
+ end
69
+ end
70
+
71
+ def user_info
72
+ {
73
+ 'name' => user_data["name"],
74
+ 'image' => user_data["tinyurl"]
75
+ }
76
+ end
77
+
78
+ def auth_hash
79
+ OmniAuth::Utils.deep_merge(super, {
80
+ 'uid' => user_data['uid'],
81
+ 'user_info' => user_info,
82
+ 'extra' => {'user_hash' => user_data}
83
+ })
84
+ end
85
+ end
86
+ end
87
+ end
@@ -9,7 +9,7 @@ module OmniAuth
9
9
  :authorize_path => '/services/oauth2/authorize',
10
10
  :access_token_path => '/services/oauth2/token'
11
11
  }
12
-
12
+
13
13
  options.merge!(:response_type => 'code', :grant_type => 'authorization_code')
14
14
 
15
15
  super(app, :salesforce, consumer_key, consumer_secret, client_options, options, &block)
@@ -16,7 +16,7 @@ module OmniAuth
16
16
  :access_token_path => "/services/oauth/getAccessToken.mg",
17
17
  :authorize_path => "/services/oauth/authorize.mg"}, options, &block)
18
18
  end
19
-
19
+
20
20
  def auth_hash
21
21
  OmniAuth::Utils.deep_merge(super, {
22
22
  'uid' => user_hash['id'],
@@ -24,15 +24,15 @@ module OmniAuth
24
24
  'extra' => { 'user_hash' => user_hash }
25
25
  })
26
26
  end
27
-
27
+
28
28
  # user info according to schema
29
29
  def user_info
30
- {
30
+ {
31
31
  'nickname' => user_hash['NickName'],
32
32
  'name' => user_hash['NickName']
33
33
  }
34
34
  end
35
-
35
+
36
36
  # info as supplied by SmugMug
37
37
  def user_hash
38
38
  @user_hash ||= MultiJson.decode(@access_token.get('/services/api/json/1.2.2/?method=smugmug.auth.checkAccessToken').body)['Auth']['User']
@@ -3,7 +3,7 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- #
6
+ #
7
7
  # Authenticate to SoundCloud via OAuth and retrieve basic
8
8
  # user information.
9
9
  #
@@ -11,12 +11,12 @@ module OmniAuth
11
11
  #
12
12
  # use OmniAuth::Strategies::SoundCloud, 'consumerkey', 'consumersecret'
13
13
  #
14
-
14
+
15
15
  class SoundCloud < OmniAuth::Strategies::OAuth
16
16
  def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
17
  super(app, :soundcloud, consumer_key, consumer_secret, {:site => 'https://api.soundcloud.com'}, options)
18
18
  end
19
-
19
+
20
20
  def auth_hash
21
21
  OmniAuth::Utils.deep_merge(super, {
22
22
  'uid' => user_hash['id'],
@@ -24,10 +24,10 @@ module OmniAuth
24
24
  'extra' => {'user_hash' => user_hash}
25
25
  })
26
26
  end
27
-
27
+
28
28
  def user_info
29
29
  user_hash = self.user_hash
30
-
30
+
31
31
  {
32
32
  'name' => user_hash['full_name'],
33
33
  'nickname' => user_hash['username'],
@@ -37,10 +37,10 @@ module OmniAuth
37
37
  'urls' => {'Website' => user_hash['website']}
38
38
  }
39
39
  end
40
-
40
+
41
41
  def user_hash
42
42
  @user_hash ||= MultiJson.decode(@access_token.get('/me.json').body)
43
43
  end
44
44
  end
45
45
  end
46
- end
46
+ end
@@ -0,0 +1,57 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to T163 via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::T163, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class T163 < OmniAuth::Strategies::OAuth
15
+
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ @api_key = consumer_key
18
+
19
+ client_options = {
20
+ :site => 'http://api.t.163.com',
21
+ :request_token_path => '/oauth/request_token',
22
+ :access_token_path => '/oauth/access_token',
23
+ :authorize_path => '/oauth/authenticate',
24
+ :realm => 'OmniAuth'
25
+ }
26
+
27
+ super(app, :t163, consumer_key, consumer_secret, client_options, options, &block)
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => user_hash['screen_name'],
33
+ 'user_info' => user_info,
34
+ 'extra' => {'user_hash' => user_hash}
35
+ })
36
+ end
37
+
38
+ def user_info
39
+ user_hash = self.user_hash
40
+ {
41
+ 'username' => user_hash['name'],
42
+ 'name' => user_hash['realName'],
43
+ 'location' => user_hash['location'],
44
+ 'image' => user_hash['profile_image_url'],
45
+ 'description' => user_hash['description'],
46
+ 'urls' => {
47
+ 'T163' => 'http://t.163.com'
48
+ }
49
+ }
50
+ end
51
+
52
+ def user_hash
53
+ @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.163.com/account/verify_credentials.json").body)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -9,15 +9,15 @@ module OmniAuth
9
9
  :site => 'https://launchpad.37signals.com/',
10
10
  :authorize_path => '/authorization/new',
11
11
  :access_token_path => '/authorization/token'
12
- }
13
-
12
+ }
13
+
14
14
  super(app, :thirty_seven_signals, client_id, client_secret, client_options, options, &block)
15
15
  end
16
-
16
+
17
17
  def user_data
18
18
  @data ||= MultiJson.decode(@access_token.get('/authorization.json'))
19
19
  end
20
-
20
+
21
21
  def user_info
22
22
  {
23
23
  'email' => user_data['identity']['email_address'],
@@ -26,7 +26,7 @@ module OmniAuth
26
26
  'name' => [user_data['identity']['first_name'], user_data['identity']['last_name']].join(' ').strip
27
27
  }
28
28
  end
29
-
29
+
30
30
  def auth_hash
31
31
  OmniAuth::Utils.deep_merge(super, {
32
32
  'uid' => user_data['identity']['id'],
@@ -0,0 +1,64 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Tqq via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::Tqq, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class Tqq < OmniAuth::Strategies::OAuth
15
+
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ @api_key = consumer_key
18
+
19
+ client_options = {
20
+ :site => 'https://open.t.qq.com',
21
+ :request_token_path => '/cgi-bin/request_token',
22
+ :access_token_path => '/cgi-bin/access_token',
23
+ :authorize_path => '/cgi-bin/authorize',
24
+ :realm => 'OmniAuth',
25
+ :scheme => :query_string,
26
+ :nonce => nonce,
27
+ :http_method => :get,
28
+ }
29
+
30
+ super(app, :tqq, consumer_key, consumer_secret, client_options, options, &block)
31
+ end
32
+
33
+ def nonce
34
+ Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32]
35
+ end
36
+
37
+ def auth_hash
38
+ OmniAuth::Utils.deep_merge(super, {
39
+ 'uid' => user_hash["data"]['uid'],
40
+ 'user_info' => user_info,
41
+ 'extra' => {'user_hash' => user_hash}
42
+ })
43
+ end
44
+
45
+ def user_info
46
+ user_hash = self.user_hash
47
+ {
48
+ 'username' => user_hash["data"]['name'],
49
+ 'name' => user_hash["data"]['nick'],
50
+ 'location' => user_hash["data"]['location'],
51
+ 'image' => user_hash["data"]['head'],
52
+ 'description' => user_hash['description'],
53
+ 'urls' => {
54
+ 'Tqq' => 't.qq.com'
55
+ }
56
+ }
57
+ end
58
+
59
+ def user_hash
60
+ @user_hash ||= MultiJson.decode(@access_token.get("http://open.t.qq.com/api/user/info?format=json").body)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -17,7 +17,7 @@ module OmniAuth
17
17
  :authorize_path => "/Oauth/Authorize",
18
18
  }, options, &block)
19
19
  end
20
-
20
+
21
21
  def auth_hash
22
22
  OmniAuth::Utils.deep_merge(super, {
23
23
  'uid' => user_hash['MemberId'],
@@ -25,17 +25,17 @@ module OmniAuth
25
25
  'extra' => { 'user_hash' => user_hash },
26
26
  })
27
27
  end
28
-
28
+
29
29
  # user info according to schema
30
30
  def user_info
31
- {
31
+ {
32
32
  'nickname' => user_hash['Nickname'],
33
33
  'first_name' => user_hash['FirstName'],
34
34
  'last_name' => user_hash['LastName'],
35
35
  'name' => [user_hash['FirstName'],user_hash['LastName']].reject{ |n| n.nil? || n.empty? }.join(' '),
36
36
  }
37
37
  end
38
-
38
+
39
39
  # info as supplied by TradeMe user summary
40
40
  def user_hash
41
41
  @user_hash ||= MultiJson.decode(@access_token.get('https://api.trademe.co.nz/v1/MyTradeMe/Summary.json').body)
@@ -0,0 +1,79 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to TSina via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::TSina, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class Tsina < OmniAuth::Strategies::OAuth
15
+
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ @api_key = consumer_key
18
+
19
+ client_options = {
20
+ :site => 'http://api.t.sina.com.cn',
21
+ :request_token_path => '/oauth/request_token',
22
+ :access_token_path => '/oauth/access_token',
23
+ :authorize_path => '/oauth/authorize',
24
+ :realm => 'OmniAuth'
25
+ }
26
+
27
+ super(app, :tsina, consumer_key, consumer_secret, client_options, options, &block)
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => @access_token.params[:user_id],
33
+ 'user_info' => user_info,
34
+ 'extra' => {'user_hash' => user_hash}
35
+ })
36
+ end
37
+
38
+ def user_info
39
+ user_hash = self.user_hash
40
+ {
41
+ 'username' => user_hash['screen_name'],
42
+ 'name' => user_hash['name'],
43
+ 'location' => user_hash['location'],
44
+ 'image' => user_hash['profile_image_url'],
45
+ 'description' => user_hash['description'],
46
+ 'urls' => {
47
+ 'Tsina' => user_hash['url']
48
+ }
49
+ }
50
+ end
51
+
52
+ # MonkeyPatch session['oauth']['tsina']['callback_confirmed'] to true
53
+ def request_phase
54
+ request_token = consumer.get_request_token(:oauth_callback => callback_url)
55
+ session['oauth'] ||= {}
56
+ session['oauth'][name.to_s] = {'callback_confirmed' => true, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
57
+ r = Rack::Response.new
58
+
59
+ if request_token.callback_confirmed?
60
+ r.redirect(request_token.authorize_url)
61
+ else
62
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
63
+ end
64
+
65
+ r.finish
66
+ rescue ::Timeout::Error => e
67
+ fail!(:timeout, e)
68
+ end
69
+
70
+ def user_hash
71
+ # http://api.t.sina.com.cn/users/show/:id.json?source=appkey
72
+ # @access_token.params[:user_id] is the UID
73
+ # @api_key is the appkey
74
+ uid = @access_token.params[:user_id]
75
+ @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.sina.com.cn/users/show/#{uid}.json?source=#{@api_key}").body)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,57 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Tsohu via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::Tsohu, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class Tsohu < OmniAuth::Strategies::OAuth
15
+
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ @api_key = consumer_key
18
+
19
+ client_options = {
20
+ :site => 'http://api.t.sohu.com',
21
+ :request_token_path => '/oauth/request_token',
22
+ :access_token_path => '/oauth/access_token',
23
+ :authorize_path => '/oauth/authorize',
24
+ :scheme => :header,
25
+ }
26
+
27
+ super(app, :tsohu, consumer_key, consumer_secret, client_options, options, &block)
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => user_hash['id'],
33
+ 'user_info' => user_info,
34
+ 'extra' => {'user_hash' => user_hash}
35
+ })
36
+ end
37
+
38
+ def user_info
39
+ user_hash = self.user_hash
40
+ {
41
+ 'username' => user_hash['screen_name'],
42
+ 'name' => user_hash['name'],
43
+ 'location' => user_hash['location'],
44
+ 'image' => user_hash['profile_image_url'],
45
+ 'description' => user_hash['description'],
46
+ 'urls' => {
47
+ 'Tsohu' => user_hash['url']
48
+ }
49
+ }
50
+ end
51
+
52
+ def user_hash
53
+ @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.sohu.com/account/verify_credentials.json").body)
54
+ end
55
+ end
56
+ end
57
+ end