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
@@ -0,0 +1,48 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Salesforce < OmniAuth::Strategies::OAuth2
6
+ def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
7
+ client_options = {
8
+ :authorize_url => 'https://login.salesforce.com/services/oauth2/authorize',
9
+ :token_url => 'https://login.salesforce.com/services/oauth2/token',
10
+ }
11
+ options.merge!(:response_type => 'code', :grant_type => 'authorization_code')
12
+ super(app, :salesforce, client_id, client_secret, client_options, options, &block)
13
+ end
14
+
15
+ def auth_hash
16
+ data = user_data
17
+ OmniAuth::Utils.deep_merge(
18
+ super, {
19
+ 'uid' => @access_token['id'],
20
+ 'credentials' => {
21
+ 'issued_at' => @access_token['issued_at'],
22
+ 'refresh_token' => @access_token.refresh_token,
23
+ 'instance_url' => @access_token['instance_url'],
24
+ 'signature' => @access_token['signature'],
25
+ },
26
+ 'extra' => {
27
+ 'user_hash' => data,
28
+ },
29
+ 'user_info' => {
30
+ 'email' => data['email'],
31
+ 'name' => data['display_name'],
32
+ },
33
+ }
34
+ )
35
+ end
36
+
37
+ def user_data
38
+ @data ||= MultiJson.decode(@access_token.get(@access_token['id']))
39
+ rescue ::OAuth2::Error => e
40
+ if e.response.status == 302
41
+ @data ||= MultiJson.decode(@access_token.get(e.response.headers['location']))
42
+ else
43
+ raise e
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,60 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ # Authenticate to SoundCloud via OAuth2 and retrieve basic
7
+ # user information.
8
+ #
9
+ # Usage:
10
+ # use OmniAuth::Strategies::SoundCloud, 'consumerkey', 'consumersecret'
11
+ class SoundCloud < OmniAuth::Strategies::OAuth2
12
+ def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
13
+ client_options = {
14
+ :site => 'https://api.soundcloud.com',
15
+ :authorize_url => 'https://soundcloud.com/connect',
16
+ :token_url => 'https://api.soundcloud.com/oauth2/token'
17
+ }
18
+ super(app, :soundcloud, consumer_key, consumer_secret, client_options, options, &block)
19
+ end
20
+
21
+ def auth_hash
22
+ OmniAuth::Utils.deep_merge(
23
+ super, {
24
+ 'uid' => user_hash['id'],
25
+ 'user_info' => user_info,
26
+ 'extra' => {
27
+ 'user_hash' => user_hash,
28
+ }
29
+ }
30
+ )
31
+ end
32
+
33
+ def user_info
34
+ user_hash = self.user_hash
35
+ {
36
+ 'name' => user_hash['full_name'],
37
+ 'nickname' => user_hash['username'],
38
+ 'location' => user_hash['city'],
39
+ 'description' => user_hash['description'],
40
+ 'image' => user_hash['avatar_url'],
41
+ 'urls' => {
42
+ 'Website' => user_hash['website'],
43
+ },
44
+ }
45
+ end
46
+
47
+ def user_hash
48
+ @user_hash ||= MultiJson.decode(@access_token.get('/me.json').body)
49
+ end
50
+
51
+ # OAuth2 by default uses 'Bearer %s' in the header
52
+ def build_access_token
53
+ access_token = super
54
+ access_token.options[:header_format] = "OAuth %s"
55
+ access_token
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -9,21 +9,31 @@ module OmniAuth
9
9
  # basic user information.
10
10
  #
11
11
  # @example Basic Usage
12
- # use OmniAuth::Strategies::TB, 'client_id', 'client_secret'
13
- class TB < OAuth2
12
+ # use OmniAuth::Strategies::TaoBao, 'client_id', 'client_secret'
13
+ class Taobao < OmniAuth::Strategies::OAuth2
14
14
  # @param [Rack Application] app standard middleware application parameter
15
15
  # @param [String] client_id the app key at taobao open platform
16
16
  # @param [String] client_secret the app secret at taobao open platform
17
17
  # @option options [String]
18
18
 
19
- def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
19
+ def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
20
20
  client_options = {
21
- :site => "https://oauth.taobao.com/",
22
- :authorize_url => "/authorize",
23
- :access_token_url => "/token"
21
+ :authorize_url => 'https://oauth.taobao.com/authorize',
22
+ :token_url => 'https://oauth.taobao.com/token',
24
23
  }
24
+ super(app, :taobao, client_id, client_secret, client_options, options, &block)
25
+ end
25
26
 
26
- super(app, :tb, client_id, client_secret, client_options, options, &block)
27
+ def auth_hash
28
+ OmniAuth::Utils.deep_merge(
29
+ super, {
30
+ 'uid' => user_data['uid'],
31
+ 'user_info' => user_info,
32
+ 'extra' => {
33
+ 'user_hash' => user_data,
34
+ },
35
+ }
36
+ )
27
37
  end
28
38
 
29
39
  def user_data
@@ -40,12 +50,12 @@ module OmniAuth
40
50
  :method => 'taobao.user.get',
41
51
  :session => @access_token.token,
42
52
  :sign_method => 'md5',
43
- :timestamp => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
53
+ :timestamp => Time.now.strftime('%Y-%m-%d %H:%M:%S'),
44
54
  :v => '2.0'
45
55
  }
46
56
  query_param = generate_sign(query_param)
47
57
  res = Net::HTTP.post_form(URI.parse(url), query_param)
48
- @data ||= MultiJson.decode(res.body)["user_get_response"]["user"]
58
+ @data ||= MultiJson.decode(res.body)['user_get_response']['user']
49
59
  end
50
60
 
51
61
  def request_phase
@@ -55,25 +65,17 @@ module OmniAuth
55
65
 
56
66
  def user_info
57
67
  {
58
- 'name' => user_data["nick"],
59
- 'email' => (user_data["email"] if user_data["email"]),
68
+ 'name' => user_data['nick'],
69
+ 'email' => (user_data['email'] if user_data['email']),
60
70
  }
61
71
  end
62
72
 
63
- def auth_hash
64
- OmniAuth::Utils.deep_merge(super, {
65
- 'uid' => user_data['uid'],
66
- 'user_info' => user_info,
67
- 'extra' => {'user_hash' => user_data}
68
- })
69
- end
70
-
71
73
  def generate_sign(params)
72
- str = client_secret + (params.sort.collect { |k, v| "#{k}#{v}" }).join + client_secret
73
- params["sign"] = Digest::MD5.hexdigest(str).upcase!
74
+ # params.sort.collect { |k, v| "#{k}#{v}" }
75
+ str = client_secret + params.sort {|a,b| "#{a[0]}"<=>"#{b[0]}"}.flatten.join + client_secret
76
+ params['sign'] = Digest::MD5.hexdigest(str).upcase!
74
77
  params
75
78
  end
76
-
77
79
  end
78
80
  end
79
81
  end
@@ -3,17 +3,29 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- class Teambox < OAuth2
7
- def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
6
+ class Teambox < OmniAuth::Strategies::OAuth2
7
+ def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
8
8
  client_options = {
9
- :site => "https://teambox.com/",
10
- :authorize_path => "/oauth/authorize",
11
- :access_token_path => "/oauth/token"
9
+ :authorize_url => 'https://teambox.com/oauth/authorize',
10
+ :token_url => 'https://teambox.com/oauth/token',
12
11
  }
13
12
  super(app, :teambox, client_id, client_secret, client_options, options, &block)
14
13
  end
14
+
15
+ def auth_hash
16
+ OmniAuth::Utils.deep_merge(
17
+ super, {
18
+ 'uid' => user_data['id'],
19
+ 'user_info' => user_info,
20
+ 'extra' => {
21
+ 'user_hash' => user_data
22
+ },
23
+ }
24
+ )
25
+ end
26
+
15
27
  def request_phase
16
- options[:scope] ||= "offline_access"
28
+ options[:scope] ||= 'offline_access'
17
29
  options[:response_type] ||= 'code'
18
30
  super
19
31
  end
@@ -24,7 +36,7 @@ module OmniAuth
24
36
  end
25
37
 
26
38
  def user_data
27
- @data ||= MultiJson.decode(@access_token.get("/api/1/account"))
39
+ @data ||= MultiJson.decode(@access_token.get('/api/1/account'))
28
40
  end
29
41
 
30
42
  def user_info
@@ -32,18 +44,8 @@ module OmniAuth
32
44
  'nickname' => user_data['username'],
33
45
  'name' => user_data['first_name'],
34
46
  'image' => user_data['avatar_url'],
35
- 'urls' => {}
36
47
  }
37
48
  end
38
-
39
- def auth_hash
40
- OmniAuth::Utils.deep_merge(super, {
41
- 'uid' => user_data['id'],
42
- 'user_info' => user_info,
43
- 'extra' => {'user_hash' => user_data}
44
- })
45
- end
46
49
  end
47
50
  end
48
51
  end
49
-
@@ -3,17 +3,27 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- class ThirtySevenSignals < OAuth2
7
- def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
6
+ class ThirtySevenSignals < OmniAuth::Strategies::OAuth2
7
+ def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
8
8
  client_options = {
9
- :site => 'https://launchpad.37signals.com/',
10
- :authorize_path => '/authorization/new',
11
- :access_token_path => '/authorization/token'
9
+ :authorize_url => 'https://launchpad.37signals.com/authorization/new',
10
+ :token_url => 'https://launchpad.37signals.com/authorization/token',
12
11
  }
13
-
14
12
  super(app, :thirty_seven_signals, client_id, client_secret, client_options, options, &block)
15
13
  end
16
14
 
15
+ def auth_hash
16
+ OmniAuth::Utils.deep_merge(
17
+ super, {
18
+ 'uid' => user_data['identity']['id'],
19
+ 'user_info' => user_info,
20
+ 'extra' => {
21
+ 'accounts' => user_data['accounts'],
22
+ }
23
+ }
24
+ )
25
+ end
26
+
17
27
  def user_data
18
28
  @data ||= MultiJson.decode(@access_token.get('/authorization.json'))
19
29
  end
@@ -23,19 +33,9 @@ module OmniAuth
23
33
  'email' => user_data['identity']['email_address'],
24
34
  'first_name' => user_data['identity']['first_name'],
25
35
  'last_name' => user_data['identity']['last_name'],
26
- 'name' => [user_data['identity']['first_name'], user_data['identity']['last_name']].join(' ').strip
36
+ 'name' => [user_data['identity']['first_name'], user_data['identity']['last_name']].join(' ').strip,
27
37
  }
28
38
  end
29
-
30
- def auth_hash
31
- OmniAuth::Utils.deep_merge(super, {
32
- 'uid' => user_data['identity']['id'],
33
- 'user_info' => user_info,
34
- 'extra' => {
35
- 'accounts' => user_data['accounts']
36
- }
37
- })
38
- end
39
39
  end
40
40
  end
41
41
  end
@@ -0,0 +1,72 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ # Authenticate to Viadeo utilizing OAuth 2.0 and retrieve
7
+ # basic user information.
8
+ #
9
+ # @example Basic Usage
10
+ # use OmniAuth::Strategies::Viadeo, 'client_id', 'client_secret'
11
+ class Viadeo < OmniAuth::Strategies::OAuth2
12
+ # @param [Rack Application] app standard middleware application parameter
13
+ # @param [String] client_id the application id as [registered on Viadeo](http://dev.viadeo.com/)
14
+ # @param [String] client_secret the application secret as registered on Facebook
15
+ def initialize(app, client_id=nil, client_secret=nil, options = {}, &block)
16
+ client_options = {
17
+ :site => 'https://api.viadeo.com/',
18
+ :authorize_url => 'https://secure.viadeo.com/oauth-provider/authorize2',
19
+ :token_url => 'https://secure.viadeo.com/oauth-provider/access_token2'
20
+ }
21
+ super(app, :viadeo, client_id, client_secret, client_options, options, &block)
22
+ end
23
+
24
+ def auth_hash
25
+ OmniAuth::Utils.deep_merge(
26
+ super, {
27
+ 'uid' => user_data['id'],
28
+ 'user_info' => user_info,
29
+ 'extra' => {
30
+ 'user_hash' => user_data,
31
+ },
32
+ }
33
+ )
34
+ end
35
+
36
+ def user_data
37
+ @data ||= MultiJson.decode(@access_token.get('/me').body)
38
+ end
39
+
40
+ def request_phase
41
+ options[:response_type] ||= 'code'
42
+ super
43
+ end
44
+
45
+ def callback_phase
46
+ options[:grant_type] ||= 'authorization_code'
47
+ super
48
+ end
49
+
50
+ def user_info
51
+ {
52
+ 'name' => user_data['name'],
53
+ 'link' => user_data['link'],
54
+ 'first_name' => user_data['first_name'],
55
+ 'last_name' => user_data['last_name'],
56
+ 'gender' => user_data['gender'],
57
+ 'nickname' => user_data['nickname'],
58
+ 'has_picture' => user_data['has_picture'] ,
59
+ 'picture_small' => user_data['picture_small'],
60
+ 'picture_large' => user_data['picture_large'],
61
+ 'headline' => user_data['headline'],
62
+ 'introduction' => user_data['introduction'],
63
+ 'interests' => user_data['interests'],
64
+ 'location' => user_data['location'],
65
+ 'is_premium' => user_data['is_premium'],
66
+ 'premium_since' => user_data['premium_since']
67
+ }
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,104 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ # Authenticate to Vkontakte utilizing OAuth 2.0 and retrieve
7
+ # basic user information.
8
+ # documentation available here:
9
+ # http://vkontakte.ru/developers.php?o=-17680044&p=Authorization&s=0
10
+ #
11
+ # @example Basic Usage
12
+ # use OmniAuth::Strategies::Vkontakte, 'API Key', 'Secret Key'
13
+ class Vkontakte < OmniAuth::Strategies::OAuth2
14
+ # @param [Rack Application] app standard middleware application parameter
15
+ # @param [String] client_id the application id as [registered in Vkontakte]
16
+ # @param [String] client_secret the application secret as [registered in Vkontakte]
17
+ def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
18
+ client_options = {
19
+ :authorize_url => 'http://api.vkontakte.ru/oauth/authorize',
20
+ :token_url => 'https://api.vkontakte.ru/oauth/token',
21
+ }
22
+ super(app, :vkontakte, client_id, client_secret, client_options, options, &block)
23
+ end
24
+
25
+ def auth_hash
26
+ # process user's info
27
+ user_data
28
+ OmniAuth::Utils.deep_merge(
29
+ super, {
30
+ 'uid' => @data['uid'],
31
+ 'user_info' => user_info,
32
+ 'extra' => user_hash,
33
+ }
34
+ )
35
+ end
36
+
37
+ def user_data
38
+ # http://vkontakte.ru/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter
39
+ @fields ||= ['uid', 'first_name', 'last_name', 'nickname', 'domain', 'sex', 'bdate', 'city', 'country', 'timezone', 'photo', 'photo_big']
40
+
41
+ # http://vkontakte.ru/developers.php?o=-1&p=getProfiles
42
+ response = @access_token.get('https://api.vkontakte.ru/method/getProfiles',
43
+ :params => {:uid => @access_token['user_id'], :fields => @fields.join(',')}, :parse => :json)
44
+ @data ||= response.parsed['response'][0]
45
+
46
+ # we need these 2 additional requests since vkontakte returns only ids of the City and Country
47
+ # http://vkontakte.ru/developers.php?o=-17680044&p=getCities
48
+ response = @access_token.get('https://api.vkontakte.ru/method/getCities',
49
+ :params => {:cids => @data['city']}, :parse => :json)
50
+ cities = response.parsed['response']
51
+ @city ||= cities.first['name'] if cities && cities.first
52
+
53
+ # http://vkontakte.ru/developers.php?o=-17680044&p=getCountries
54
+ response = @access_token.get('https://api.vkontakte.ru/method/getCountries',
55
+ :params => {:cids => @data['country']}, :parse => :json)
56
+ countries = response.parsed['response']
57
+ @country ||= countries.first['name'] if countries && countries.first
58
+ end
59
+
60
+ def request_phase
61
+ options[:response_type] ||= 'code'
62
+ super
63
+ end
64
+
65
+ def build_access_token
66
+ token = super
67
+ # indicates that `offline` permission was granted, no need to the token refresh
68
+ if token.expires_in == 0
69
+ ::OAuth2::AccessToken.new(token.client, token.token,
70
+ token.params.reject{|k,_| [:refresh_token, :expires_in, :expires_at, :expires].include? k.to_sym}
71
+ )
72
+ else
73
+ token
74
+ end
75
+ end
76
+
77
+ def user_info
78
+ {
79
+ 'first_name' => @data['first_name'],
80
+ 'last_name' => @data['last_name'],
81
+ 'name' => "#{@data['first_name']} #{@data['last_name']}".strip,
82
+ 'nickname' => @data['nickname'],
83
+ 'birth_date' => @data['bdate'],
84
+ 'image' => @data['photo'],
85
+ 'location' => "#{@country}, #{@city}",
86
+ 'urls' => {
87
+ 'Vkontakte' => "http://vkontakte.ru/#{@data['domain']}",
88
+ },
89
+ }
90
+ end
91
+
92
+ def user_hash
93
+ {
94
+ 'user_hash' => {
95
+ 'gender' => @data['sex'],
96
+ 'timezone' => @data['timezone'],
97
+ # 200px maximum resolution of the avatar (http://vkontakte.ru/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter)
98
+ 'photo_big' => @data['photo_big'],
99
+ }
100
+ }
101
+ end
102
+ end
103
+ end
104
+ end