oa-oauth 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -10,31 +10,31 @@ module OmniAuth
10
10
  # use OmniAuth::Strategies::Instagram, 'client_id', 'client_secret'
11
11
  class Instagram < OAuth2
12
12
  # @option options [String] :scope separate the scopes by a space
13
- def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
13
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
14
14
  client_options = {
15
15
  :site => "https://api.instagram.com/",
16
16
  :authorize_url => "/oauth/authorize",
17
17
  :access_token_url => "/oauth/access_token"
18
18
  }
19
-
19
+
20
20
  super(app, :instagram, client_id, client_secret, client_options, options, &block)
21
21
  end
22
-
22
+
23
23
  def request_phase
24
24
  options[:scope] ||= "basic"
25
25
  options[:response_type] ||= 'code'
26
26
  super
27
27
  end
28
-
28
+
29
29
  def callback_phase
30
30
  options[:grant_type] ||= 'authorization_code'
31
31
  super
32
32
  end
33
-
33
+
34
34
  def user_data
35
35
  @data ||= MultiJson.decode(@access_token.get("/v1/users/self"))
36
36
  end
37
-
37
+
38
38
  def user_info
39
39
  {
40
40
  'nickname' => user_data['data']['username'],
@@ -43,7 +43,7 @@ module OmniAuth
43
43
  'urls' => {}
44
44
  }
45
45
  end
46
-
46
+
47
47
  def auth_hash
48
48
  OmniAuth::Utils.deep_merge(super, {
49
49
  'uid' => user_data['data']['id'],
@@ -4,7 +4,7 @@ require 'multi_json'
4
4
  module OmniAuth
5
5
  module Strategies
6
6
  class Instapaper < OmniAuth::Strategies::XAuth
7
-
7
+
8
8
  def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
9
9
  client_options = {
10
10
  :title => 'Instapaper',
@@ -13,27 +13,27 @@ module OmniAuth
13
13
  }
14
14
  super(app, :instapaper, consumer_key, consumer_secret, client_options, options, &block)
15
15
  end
16
-
16
+
17
17
  protected
18
-
18
+
19
19
  def user_data
20
20
  @data ||= MultiJson.decode(@access_token.get('/api/1/account/verify_credentials').body)[0]
21
21
  end
22
-
22
+
23
23
  def user_info
24
24
  {
25
25
  'nickname' => user_data['username'],
26
26
  'name' => user_data['username']
27
27
  }
28
28
  end
29
-
29
+
30
30
  def auth_hash
31
31
  OmniAuth::Utils.deep_merge(super, {
32
32
  'uid' => user_data['user_id'],
33
33
  'user_info' => user_info
34
34
  })
35
35
  end
36
-
36
+
37
37
  end
38
38
  end
39
39
  end
@@ -1,4 +1,4 @@
1
- require 'nokogiri'
1
+ require 'multi_xml'
2
2
  require 'omniauth/oauth'
3
3
 
4
4
  module OmniAuth
@@ -15,22 +15,21 @@ module OmniAuth
15
15
 
16
16
  client_options[:authorize_path] = '/uas/oauth/authenticate' unless options[:sign_in] == false
17
17
 
18
- '/uas/oauth/authorize'
19
18
  super(app, :linked_in, consumer_key, consumer_secret, client_options, options, &block)
20
19
  end
21
-
20
+
22
21
  def auth_hash
23
22
  hash = user_hash(@access_token)
24
-
23
+
25
24
  OmniAuth::Utils.deep_merge(super, {
26
25
  'uid' => hash.delete('id'),
27
26
  'user_info' => hash
28
27
  })
29
28
  end
30
-
29
+
31
30
  def user_hash(access_token)
32
- person = Nokogiri::XML::Document.parse(@access_token.get('/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url)').body).xpath('person')
33
-
31
+ person = MulitXml.parse(@access_token.get('/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url)').body).xpath('person')
32
+
34
33
  hash = {
35
34
  'id' => person.xpath('id').text,
36
35
  'first_name' => person.xpath('first-name').text,
@@ -39,15 +38,16 @@ module OmniAuth
39
38
  'location' => person.xpath('location/name').text,
40
39
  'image' => person.xpath('picture-url').text,
41
40
  'description' => person.xpath('headline').text,
41
+ 'public_profile_url' => person.xpath('public-profile-url').text,
42
42
  'urls' => person.css('member-url-resources member-url').inject({}) do |h,element|
43
43
  h[element.xpath('name').text] = element.xpath('url').text
44
44
  h
45
45
  end
46
46
  }
47
-
47
+
48
48
  hash['urls']['LinkedIn'] = person.xpath('public-profile-url').text
49
49
  hash['name'] = "#{hash['first_name']} #{hash['last_name']}"
50
-
50
+
51
51
  hash
52
52
  end
53
53
  end
@@ -3,7 +3,7 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- #
6
+ #
7
7
  # Authenticate to Miso via OAuth and retrieve basic
8
8
  # user information.
9
9
  #
@@ -15,7 +15,7 @@ module OmniAuth
15
15
  def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
16
  super(app, :miso, consumer_key, consumer_secret, {:site => 'https://gomiso.com'}, options)
17
17
  end
18
-
18
+
19
19
  def auth_hash
20
20
  OmniAuth::Utils.deep_merge(super, {
21
21
  'uid' => user_hash['id'],
@@ -23,8 +23,8 @@ module OmniAuth
23
23
  'extra' => {'user_hash' => user_hash}
24
24
  })
25
25
  end
26
-
27
- def user_info
26
+
27
+ def user_info
28
28
  {
29
29
  'nickname' => user_hash['username'],
30
30
  'name' => user_hash['full_name'],
@@ -32,7 +32,7 @@ module OmniAuth
32
32
  'description' => user_hash['tagline'],
33
33
  }
34
34
  end
35
-
35
+
36
36
  def user_hash
37
37
  @user_hash ||= MultiJson.decode(@access_token.get('/api/oauth/v1/users/show.json').body)['user']
38
38
  end
@@ -10,35 +10,35 @@ module OmniAuth
10
10
  # use OmniAuth::Strategies::Mixi, 'client_id', 'client_secret'
11
11
  class Mixi < OAuth2
12
12
  # @option options [String] :scope separate the scopes by a space
13
- def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
13
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
14
14
  client_options = {
15
15
  :site => "https://mixi.jp/",
16
16
  :authorize_url => "/connect_authorize.pl",
17
17
  :access_token_url => "https://secure.mixi-platform.com/2/token"
18
18
  }
19
-
19
+
20
20
  super(app, :mixi, client_id, client_secret, client_options, options, &block)
21
21
  end
22
-
22
+
23
23
  def user_data
24
24
  @data ||= MultiJson.decode(@access_token.get(
25
25
  "http://api.mixi-platform.com/2/people/@me/@self",
26
26
  {'oauth_token' => @access_token.token}
27
27
  ))
28
28
  end
29
-
29
+
30
30
  def request_phase
31
31
  options[:scope] ||= "r_profile"
32
- options[:display] ||= "pc"
32
+ options[:display] ||= "pc"
33
33
  options[:response_type] ||= 'code'
34
34
  super
35
35
  end
36
-
36
+
37
37
  def callback_phase
38
38
  options[:grant_type] ||= 'authorization_code'
39
39
  super
40
40
  end
41
-
41
+
42
42
  def user_info
43
43
  {
44
44
  'nickname' => user_data['entry']['displayName'],
@@ -46,7 +46,7 @@ module OmniAuth
46
46
  'urls' => {:profile => user_data['entry']['profileUrl']}
47
47
  }
48
48
  end
49
-
49
+
50
50
  def auth_hash
51
51
  OmniAuth::Utils.deep_merge(super, {
52
52
  'uid' => user_data['entry']['id'],
@@ -12,26 +12,26 @@ module OmniAuth
12
12
  # OAuth 2.0.
13
13
  class OAuth2
14
14
  include OmniAuth::Strategy
15
-
15
+
16
16
  # The options passed in to the strategy.
17
17
  attr_accessor :options
18
18
  # The `OAuth2::Client` for this strategy.
19
19
  attr_accessor :client_id, :client_secret, :client_options
20
-
20
+
21
21
  # An error that is indicated in the OAuth 2.0 callback.
22
- # This could be a `redirect_uri_mismatch` or other
22
+ # This could be a `redirect_uri_mismatch` or other
23
23
  class CallbackError < StandardError
24
24
  attr_accessor :error, :error_reason, :error_uri
25
-
25
+
26
26
  def initialize(error, error_reason=nil, error_uri=nil)
27
27
  self.error = error
28
28
  self.error_reason = error_reason
29
29
  self.error_uri = error_uri
30
30
  end
31
31
  end
32
-
32
+
33
33
  # Initialize a new OAuth 2.0 authentication provider.
34
-
34
+
35
35
  # @param [Rack Application] app standard middleware application argument
36
36
  # @param [String] name the name for this provider to be used in its URL, e.g. `/auth/name`
37
37
  # @param [String] client_id the client/application ID of this provider
@@ -43,17 +43,17 @@ module OmniAuth
43
43
  self.client_options = client_options
44
44
  super
45
45
  end
46
-
46
+
47
47
  def client
48
48
  ::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
49
49
  end
50
-
50
+
51
51
  def callback_url
52
52
  full_host + callback_path
53
53
  end
54
54
 
55
55
  protected
56
-
56
+
57
57
  def request_phase
58
58
  redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
59
59
  end
@@ -62,19 +62,19 @@ module OmniAuth
62
62
  if request.params['error'] || request.params['error_reason']
63
63
  raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
64
64
  end
65
-
65
+
66
66
  @access_token = build_access_token
67
-
67
+
68
68
  if @access_token.expires? && @access_token.expires_in <= 0
69
- client.request(:post, client.access_token_url, {
69
+ client.request(:post, client.access_token_url, {
70
70
  'client_id' => client_id,
71
- 'grant_type' => 'refresh_token',
71
+ 'grant_type' => 'refresh_token',
72
72
  'client_secret' => client_secret,
73
- 'refresh_token' => @access_token.refresh_token
73
+ 'refresh_token' => @access_token.refresh_token
74
74
  }.merge(options))
75
75
  @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
76
76
  end
77
-
77
+
78
78
  super
79
79
  rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
80
80
  fail!(:invalid_credentials, e)
@@ -83,16 +83,15 @@ module OmniAuth
83
83
  end
84
84
 
85
85
  def build_access_token
86
- verifier = request.params['code']
86
+ verifier = request.params['code']
87
87
  client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
88
88
  end
89
-
89
+
90
90
  def auth_hash
91
- OmniAuth::Utils.deep_merge(super, {
92
- 'credentials' => {
93
- 'token' => @access_token.token
94
- }
95
- })
91
+ credentials = {'token' => @access_token.token}
92
+ credentials.merge('refresh_token' => @access_token.refresh_token) if @access_token.expires?
93
+
94
+ OmniAuth::Utils.deep_merge(super, {'credentials' => credentials})
96
95
  end
97
96
  end
98
97
  end
@@ -0,0 +1,69 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to qzone (QQ) via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::Qzone, 'consumerkey', 'consumersecret'
13
+ #
14
+ class Qzone < OmniAuth::Strategies::OAuth
15
+ # Initialize the middleware
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ client_options = {
18
+ :site => 'http://openapi.qzone.qq.com',
19
+ :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
24
+ }
25
+
26
+ options[:authorize_params] = {:oauth_consumer_key => consumer_key}
27
+ super(app, :qzone, consumer_key, consumer_secret, client_options, options)
28
+ end
29
+
30
+ #HACK qzone is using a none-standard parameter oauth_overicode
31
+ def consumer_options
32
+ @consumer_options[:access_token_path] = '/oauth/qzoneoauth_access_token?oauth_vericode=' + request['oauth_vericode'] if request['oauth_vericode']
33
+ @consumer_options
34
+ end
35
+
36
+ def callback_phase
37
+ session['oauth'][name.to_s]['callback_confirmed'] = true
38
+ super
39
+ end
40
+
41
+ def auth_hash
42
+ ui = user_info
43
+ OmniAuth::Utils.deep_merge(super, {
44
+ 'uid' => ui['uid'],
45
+ 'user_info' => ui,
46
+ 'extra' => {'user_hash' => user_hash}
47
+ })
48
+ end
49
+
50
+ def user_info
51
+ user_hash = self.user_hash
52
+ {
53
+ 'uid' => @access_token.params[:openid],
54
+ 'nickname' => user_hash['nickname'],
55
+ 'name' => user_hash['nickname'],
56
+ 'image' => user_hash['figureurl'],
57
+ 'urls' => {
58
+ 'figureurl_1' => user_hash['figureurl_1'],
59
+ 'figureurl_2' => user_hash['figureurl_2'],
60
+ }
61
+ }
62
+ end
63
+
64
+ def user_hash
65
+ @user_hash ||= MultiJson.decode(@access_token.get("/user/get_user_info?format=json&openid=#{@access_token.params[:openid]}").body)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,45 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Rdio via OAuth and retrieve basic user information.
8
+ # Usage:
9
+ # use OmniAuth::Strategies::Rdio, 'consumerkey', 'consumersecret'
10
+ #
11
+ class Rdio < OmniAuth::Strategies::OAuth
12
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
13
+ opts = {
14
+ :site => 'http://api.rdio.com',
15
+ :request_token_path => "/oauth/request_token",
16
+ :access_token_path => "/oauth/access_token",
17
+ :authorize_url => "https://www.rdio.com/oauth/authorize"
18
+ }
19
+ super(app, :rdio, consumer_key, consumer_secret, opts, options, &block)
20
+ end
21
+
22
+ def auth_hash
23
+ OmniAuth::Utils.deep_merge(super, {
24
+ 'uid' => user_hash['key'],
25
+ 'user_info' => user_info,
26
+ 'extra' => { 'user_hash' => user_hash }
27
+ })
28
+ end
29
+
30
+ def user_info
31
+ user = user_hash
32
+ {
33
+ 'nickname' => user['username'],
34
+ 'first_name' => user['firstName'],
35
+ 'last_name' => user['lastName'],
36
+ 'name' => "#{user['firstName']} #{user['lastName']}"
37
+ }
38
+ end
39
+
40
+ def user_hash
41
+ @user_hash ||= MultiJson.decode(@access_token.post("http://api.rdio.com/1/", { :method => 'currentUser', :extras => 'username' }).body)['result']
42
+ end
43
+ end
44
+ end
45
+ end