oauth 0.5.4 → 0.5.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5bc9d7d87cd97024d39e6cd354fd2dc1ae44f4d1
4
- data.tar.gz: d3992c9bb4d3142d2a7d4e70f76836fbe1b94b56
2
+ SHA256:
3
+ metadata.gz: 9bd785e08f2a318da373f07b79fe6583ed3e8c26bcc92c5e1513ee615ea0f037
4
+ data.tar.gz: 3e9f81feb37166f4fec398d20e8b4de882b6e1e2304f893c033b920ab737616a
5
5
  SHA512:
6
- metadata.gz: 2e5602e42f41ed1312cddd17ce4ef9473fcac93152e64c16e6e30c151171e15702394e74534657e2b67b6b51f20767b698e877a707a144cf5d904445074e8ce9
7
- data.tar.gz: fc164eae28c093eb3e777e469d70bf2527cd058c6772b304866fbdd7df686048307e65ad4c9c786db75035153e34b21755af7a1eecc094227c40f2dee388d0d2
6
+ metadata.gz: 6bc060045ecb7ca1c47263f4bab7fde62c3a173ccf7ea6e1dacc5ac4e814ecea88e4b2f594f6bd2a7d80f9393e1295b1a5cbc85f3eb74c35cbb348da6f32cfe6
7
+ data.tar.gz: c96c9abd68f71cca8d33db21e3d68f1c7fe98898dba924fd440bf882280d99d39beb7a0751be913bb0f18872875ca8098792733f1717ff8d127156a99a69f039
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == Status
4
4
 
5
- {<img src="https://travis-ci.org/oauth-xx/oauth-ruby.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/oauth-xx/oauth-ruby]
5
+ {<img src="https://travis-ci.org/oauth-xx/oauth-ruby.svg?branch=master" alt="Build Status" />}[https://travis-ci.com/github/oauth-xx/oauth-ruby]
6
6
 
7
7
 
8
8
 
@@ -28,26 +28,28 @@ As a matter of fact it has been pulled out from an OAuth Rails GEM (https://ruby
28
28
 
29
29
  We need to specify the oauth_callback url explicitly, otherwise it defaults to "oob" (Out of Band)
30
30
 
31
- @callback_url = "http://127.0.0.1:3000/oauth/callback"
31
+ callback_url = "http://127.0.0.1:3000/oauth/callback"
32
32
 
33
- Create a new consumer instance by passing it a configuration hash:
33
+ Create a new `OAuth::Consumer` instance by passing it a configuration hash:
34
34
 
35
- @consumer = OAuth::Consumer.new("key","secret", :site => "https://agree2")
35
+ oauth_consumer = OAuth::Consumer.new("key", "secret", :site => "https://agree2")
36
36
 
37
37
  Start the process by requesting a token
38
38
 
39
- @request_token = @consumer.get_request_token(:oauth_callback => @callback_url)
39
+ request_token = oauth_consumer.get_request_token(:oauth_callback => callback_url)
40
40
 
41
41
  session[:token] = request_token.token
42
42
  session[:token_secret] = request_token.secret
43
- redirect_to @request_token.authorize_url(:oauth_callback => @callback_url)
43
+ redirect_to request_token.authorize_url(:oauth_callback => callback_url)
44
44
 
45
45
  When user returns create an access_token
46
46
 
47
47
  hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
48
- request_token = OAuth::RequestToken.from_hash(@consumer, hash)
49
- @access_token = @request_token.get_access_token
50
- @photos = @access_token.get('/photos.xml')
48
+ request_token = OAuth::RequestToken.from_hash(oauth_consumer, hash)
49
+ access_token = request_token.get_access_token
50
+ # For 3-legged authorization, flow oauth_verifier is passed as param in callback
51
+ # access_token = request_token.get_access_token(oauth_verifier: params[:oauth_verifier])
52
+ @photos = access_token.get('/photos.xml')
51
53
 
52
54
  Now that you have an access token, you can use Typhoeus to interact with the OAuth provider if you choose.
53
55
 
data/lib/oauth.rb CHANGED
@@ -7,5 +7,6 @@ require 'oauth/oauth'
7
7
 
8
8
  require 'oauth/client/helper'
9
9
  require 'oauth/signature/hmac/sha1'
10
+ require 'oauth/signature/hmac/sha256'
10
11
  require 'oauth/signature/rsa/sha1'
11
12
  require 'oauth/request_proxy/mock_request'
@@ -27,7 +27,7 @@ module OAuth::Client
27
27
  end
28
28
 
29
29
  def oauth_parameters
30
- {
30
+ out = {
31
31
  'oauth_body_hash' => options[:body_hash],
32
32
  'oauth_callback' => options[:oauth_callback],
33
33
  'oauth_consumer_key' => options[:consumer].key,
@@ -38,7 +38,13 @@ module OAuth::Client
38
38
  'oauth_verifier' => options[:oauth_verifier],
39
39
  'oauth_version' => (options[:oauth_version] || '1.0'),
40
40
  'oauth_session_handle' => options[:oauth_session_handle]
41
- }.reject { |k,v| v.to_s == "" }
41
+ }
42
+ allowed_empty_params = options[:allow_empty_params]
43
+ if allowed_empty_params != true && !allowed_empty_params.kind_of?(Array)
44
+ allowed_empty_params = allowed_empty_params == false ? [] : [allowed_empty_params]
45
+ end
46
+ out.select! { |k,v| v.to_s != '' || allowed_empty_params == true || allowed_empty_params.include?(k) }
47
+ out
42
48
  end
43
49
 
44
50
  def signature(extra_options = {})
@@ -8,11 +8,21 @@ require 'cgi'
8
8
  module OAuth
9
9
  class Consumer
10
10
  # determine the certificate authority path to verify SSL certs
11
- CA_FILES = %W(#{ENV['SSL_CERT_FILE']} /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt)
12
- CA_FILES.each do |ca_file|
13
- if File.exist?(ca_file)
14
- CA_FILE = ca_file
15
- break
11
+ if ENV['SSL_CERT_FILE']
12
+ if File.exist?(ENV['SSL_CERT_FILE'])
13
+ CA_FILE = ENV['SSL_CERT_FILE']
14
+ else
15
+ raise "The SSL CERT provided does not exist."
16
+ end
17
+ end
18
+
19
+ if !defined?(CA_FILE)
20
+ CA_FILES = %W(/etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt /usr/share/curl/curl-ca-bundle.crt)
21
+ CA_FILES.each do |ca_file|
22
+ if File.exist?(ca_file)
23
+ CA_FILE = ca_file
24
+ break
25
+ end
16
26
  end
17
27
  end
18
28
  CA_FILE = nil unless defined?(CA_FILE)
@@ -23,6 +33,7 @@ module OAuth
23
33
 
24
34
  # default paths on site. These are the same as the defaults set up by the generators
25
35
  :request_token_path => '/oauth/request_token',
36
+ :authenticate_path => '/oauth/authenticate',
26
37
  :authorize_path => '/oauth/authorize',
27
38
  :access_token_path => '/oauth/access_token',
28
39
 
@@ -230,7 +241,14 @@ module OAuth
230
241
  when (300..399)
231
242
  # this is a redirect
232
243
  uri = URI.parse(response['location'])
233
- response.error! if uri.path == path # careful of those infinite redirects
244
+ our_uri = URI.parse(site)
245
+
246
+ if uri.path == path && our_uri.host != uri.host
247
+ options[:site] = "#{uri.scheme}://#{uri.host}"
248
+ @http = create_http
249
+ end
250
+
251
+ response.error! if uri.path == path && our_uri.host == uri.host # careful of those infinite redirects
234
252
  self.token_request(http_method, uri.path, token, request_options, arguments)
235
253
  when (400..499)
236
254
  raise OAuth::Unauthorized, response
@@ -266,6 +284,10 @@ module OAuth
266
284
  @options[:request_token_path]
267
285
  end
268
286
 
287
+ def authenticate_path
288
+ @options[:authenticate_path]
289
+ end
290
+
269
291
  def authorize_path
270
292
  @options[:authorize_path]
271
293
  end
@@ -283,6 +305,14 @@ module OAuth
283
305
  @options.has_key?(:request_token_url)
284
306
  end
285
307
 
308
+ def authenticate_url
309
+ @options[:authenticate_url] || site + authenticate_path
310
+ end
311
+
312
+ def authenticate_url?
313
+ @options.has_key?(:authenticate_url)
314
+ end
315
+
286
316
  def authorize_url
287
317
  @options[:authorize_url] || site + authorize_path
288
318
  end
@@ -330,15 +360,18 @@ module OAuth
330
360
 
331
361
  http_object.use_ssl = (our_uri.scheme == 'https')
332
362
 
333
- if @options[:ca_file] || CA_FILE
334
- http_object.ca_file = @options[:ca_file] || CA_FILE
363
+ if @options[:no_verify]
364
+ http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
365
+ else
366
+ ca_file = @options[:ca_file] || CA_FILE
367
+ if ca_file
368
+ http_object.ca_file = ca_file
369
+ end
335
370
  http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER
336
371
  http_object.verify_depth = 5
337
- else
338
- http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
339
372
  end
340
373
 
341
- http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 30
374
+ http_object.read_timeout = http_object.open_timeout = @options[:timeout] || 60
342
375
  http_object.open_timeout = @options[:open_timeout] if @options[:open_timeout]
343
376
  http_object.ssl_version = @options[:ssl_version] if @options[:ssl_version]
344
377
  http_object.set_debug_output(debug_output) if debug_output
@@ -60,7 +60,7 @@ module OAuth::RequestProxy
60
60
  params << header_params.to_query
61
61
  params << request.query_string unless query_string_blank?
62
62
 
63
- if request.post? && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
63
+ if raw_post_signature?
64
64
  params << request.raw_post
65
65
  end
66
66
  end
@@ -72,6 +72,10 @@ module OAuth::RequestProxy
72
72
  reject { |kv| kv[0] == 'oauth_signature'}
73
73
  end
74
74
 
75
+ def raw_post_signature?
76
+ (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
77
+ end
78
+
75
79
  protected
76
80
 
77
81
  def query_params
@@ -0,0 +1,17 @@
1
+ require 'oauth/signature/base'
2
+
3
+ module OAuth::Signature::HMAC
4
+ class SHA256 < OAuth::Signature::Base
5
+ implements 'hmac-sha256'
6
+
7
+ def body_hash
8
+ Base64.encode64(OpenSSL::Digest::SHA256.digest(request.body || '')).chomp.gsub(/\n/,'')
9
+ end
10
+
11
+ private
12
+
13
+ def digest
14
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret, signature_base_string)
15
+ end
16
+ end
17
+ end
@@ -8,7 +8,14 @@ module OAuth
8
8
  return nil if self.token.nil?
9
9
 
10
10
  params = (params || {}).merge(:oauth_token => self.token)
11
- build_authorize_url(consumer.authorize_url, params)
11
+ build_url(consumer.authorize_url, params)
12
+ end
13
+
14
+ def authenticate_url(params = nil)
15
+ return nil if self.token.nil?
16
+
17
+ params = (params || {}).merge(:oauth_token => self.token)
18
+ build_url(consumer.authenticate_url, params)
12
19
  end
13
20
 
14
21
  def callback_confirmed?
@@ -23,8 +30,8 @@ module OAuth
23
30
 
24
31
  protected
25
32
 
26
- # construct an authorization url
27
- def build_authorize_url(base_url, params)
33
+ # construct an authorization or authentication url
34
+ def build_url(base_url, params)
28
35
  uri = URI.parse(base_url.to_s)
29
36
  queries = {}
30
37
  queries = Hash[URI.decode_www_form(uri.query)] if uri.query
data/lib/oauth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OAuth
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pelle Braendgaard
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2017-12-08 00:00:00.000000000 Z
18
+ date: 2021-04-02 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -122,6 +122,9 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.9.12
125
+ - - "<="
126
+ - !ruby/object:Gem::Version
127
+ version: 1.1.0
125
128
  type: :development
126
129
  prerelease: false
127
130
  version_requirements: !ruby/object:Gem::Requirement
@@ -129,6 +132,9 @@ dependencies:
129
132
  - - ">="
130
133
  - !ruby/object:Gem::Version
131
134
  version: 0.9.12
135
+ - - "<="
136
+ - !ruby/object:Gem::Version
137
+ version: 1.1.0
132
138
  - !ruby/object:Gem::Dependency
133
139
  name: typhoeus
134
140
  requirement: !ruby/object:Gem::Requirement
@@ -278,6 +284,7 @@ files:
278
284
  - lib/oauth/signature.rb
279
285
  - lib/oauth/signature/base.rb
280
286
  - lib/oauth/signature/hmac/sha1.rb
287
+ - lib/oauth/signature/hmac/sha256.rb
281
288
  - lib/oauth/signature/plaintext.rb
282
289
  - lib/oauth/signature/rsa/sha1.rb
283
290
  - lib/oauth/token.rb
@@ -287,10 +294,15 @@ files:
287
294
  - lib/oauth/tokens/server_token.rb
288
295
  - lib/oauth/tokens/token.rb
289
296
  - lib/oauth/version.rb
290
- homepage:
297
+ homepage: https://github.com/oauth-xx/oauth-ruby
291
298
  licenses:
292
299
  - MIT
293
- metadata: {}
300
+ metadata:
301
+ bug_tracker_uri: https://github.com/oauth-xx/oauth-ruby/issues
302
+ changelog_uri: https://github.com/oauth-xx/oauth-ruby/blob/master/HISTORY
303
+ documentation_uri: https://rdoc.info/github/oauth-xx/oauth-ruby/master/frames
304
+ homepage_uri: https://github.com/oauth-xx/oauth-ruby
305
+ source_code_uri: https://github.com/oauth-xx/oauth-ruby
294
306
  post_install_message:
295
307
  rdoc_options: []
296
308
  require_paths:
@@ -306,8 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
318
  - !ruby/object:Gem::Version
307
319
  version: '0'
308
320
  requirements: []
309
- rubyforge_project:
310
- rubygems_version: 2.2.2
321
+ rubygems_version: 3.0.3
311
322
  signing_key:
312
323
  specification_version: 4
313
324
  summary: OAuth Core Ruby implementation