signet 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/compat/digest/hmac.rb +9 -0
- data/lib/signet/oauth_1.rb +6 -3
- data/lib/signet/oauth_1/client.rb +1 -0
- data/lib/signet/oauth_1/credential.rb +1 -1
- data/lib/signet/version.rb +1 -1
- data/spec/signet/oauth_1/client_spec.rb +8 -8
- data/spec/signet/oauth_1/credential_spec.rb +2 -2
- data/spec/signet/oauth_1/services/google_spec.rb +4 -2
- data/spec/signet/oauth_1_spec.rb +14 -20
- metadata +4 -4
data/CHANGELOG
CHANGED
data/lib/compat/digest/hmac.rb
CHANGED
@@ -37,6 +37,15 @@
|
|
37
37
|
#
|
38
38
|
|
39
39
|
require 'digest'
|
40
|
+
if !''.respond_to?(:bytesize) || !''.respond_to?(:bytes)
|
41
|
+
begin
|
42
|
+
require 'backports/1.8.7'
|
43
|
+
rescue LoadError
|
44
|
+
STDERR.puts "Please install backports:"
|
45
|
+
STDERR.puts "sudo gem install backports"
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
end
|
40
49
|
|
41
50
|
unless defined?(Digest::HMAC)
|
42
51
|
module Digest
|
data/lib/signet/oauth_1.rb
CHANGED
@@ -284,7 +284,9 @@ module Signet #:nodoc:
|
|
284
284
|
# be a temporary credential secret when obtaining a token credential
|
285
285
|
# for the first time
|
286
286
|
base_string = self.generate_base_string(method, uri, parameters)
|
287
|
-
signature_method =
|
287
|
+
signature_method = (
|
288
|
+
parameters.inject({}) { |h,(k,v)| h[k]=v; h }
|
289
|
+
)['oauth_signature_method']
|
288
290
|
case signature_method
|
289
291
|
when 'HMAC-SHA1'
|
290
292
|
require 'signet/oauth_1/signature_methods/hmac_sha1'
|
@@ -358,8 +360,9 @@ module Signet #:nodoc:
|
|
358
360
|
parsed_uri = Addressable::URI.parse(authorization_uri)
|
359
361
|
query_values = parsed_uri.query_values || {}
|
360
362
|
if options[:additional_parameters]
|
361
|
-
query_values =
|
362
|
-
|
363
|
+
query_values = query_values.merge(
|
364
|
+
options[:additional_parameters].inject({}) { |h,(k,v)| h[k]=v; h }
|
365
|
+
)
|
363
366
|
end
|
364
367
|
if temporary_credential_key
|
365
368
|
query_values['oauth_token'] = temporary_credential_key
|
@@ -75,7 +75,7 @@ module Signet #:nodoc:
|
|
75
75
|
args = args.first.to_ary
|
76
76
|
end
|
77
77
|
if args.all? { |value| value.kind_of?(Array) }
|
78
|
-
parameters =
|
78
|
+
parameters = args.inject({}) { |h,(k,v)| h[k]=v; h }
|
79
79
|
@key = key_from_hash.call(parameters)
|
80
80
|
@secret = secret_from_hash.call(parameters)
|
81
81
|
elsif args.size == 2
|
data/lib/signet/version.rb
CHANGED
@@ -560,9 +560,9 @@ describe Signet::OAuth1::Client, 'configured' do
|
|
560
560
|
headers.each do |(header, value)|
|
561
561
|
authorization_header = value if header == 'Authorization'
|
562
562
|
end
|
563
|
-
parameters =
|
563
|
+
parameters = ::Signet::OAuth1.parse_authorization_header(
|
564
564
|
authorization_header
|
565
|
-
)]
|
565
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
566
566
|
parameters.should_not have_key('oauth_client_credential_key')
|
567
567
|
parameters.should_not have_key('oauth_temporary_credential_key')
|
568
568
|
parameters.should_not have_key('oauth_token')
|
@@ -589,9 +589,9 @@ describe Signet::OAuth1::Client, 'configured' do
|
|
589
589
|
headers.each do |(header, value)|
|
590
590
|
authorization_header = value if header == 'Authorization'
|
591
591
|
end
|
592
|
-
parameters =
|
592
|
+
parameters = ::Signet::OAuth1.parse_authorization_header(
|
593
593
|
authorization_header
|
594
|
-
)]
|
594
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
595
595
|
parameters.should_not have_key('oauth_client_credential_key')
|
596
596
|
parameters.should_not have_key('oauth_temporary_credential_key')
|
597
597
|
parameters.should_not have_key('oauth_callback')
|
@@ -627,9 +627,9 @@ describe Signet::OAuth1::Client, 'configured' do
|
|
627
627
|
authorization_header = value if header == 'Authorization'
|
628
628
|
end
|
629
629
|
merge_body(body).should == ''
|
630
|
-
parameters =
|
630
|
+
parameters = ::Signet::OAuth1.parse_authorization_header(
|
631
631
|
authorization_header
|
632
|
-
)]
|
632
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
633
633
|
parameters.should_not have_key('oauth_client_credential_key')
|
634
634
|
parameters.should_not have_key('oauth_temporary_credential_key')
|
635
635
|
parameters.should_not have_key('oauth_token_credential_key')
|
@@ -669,9 +669,9 @@ describe Signet::OAuth1::Client, 'configured' do
|
|
669
669
|
authorization_header = value if header == 'Authorization'
|
670
670
|
end
|
671
671
|
merge_body(body).should == 'file=vacation.jpg&size=original'
|
672
|
-
parameters =
|
672
|
+
parameters = ::Signet::OAuth1.parse_authorization_header(
|
673
673
|
authorization_header
|
674
|
-
)]
|
674
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
675
675
|
parameters.should_not have_key('oauth_client_credential_key')
|
676
676
|
parameters.should_not have_key('oauth_temporary_credential_key')
|
677
677
|
parameters.should_not have_key('oauth_token_credential_key')
|
@@ -66,7 +66,7 @@ describe Signet::OAuth1::Credential, 'with a Hash for initialization' do
|
|
66
66
|
it 'should allow parameters to be specified as an implicit Hash' do
|
67
67
|
class ParameterHashSet
|
68
68
|
def initialize(parameters)
|
69
|
-
@parameters =
|
69
|
+
@parameters = parameters.inject({}) { |h,(k,v)| h[k]=v; h }
|
70
70
|
end
|
71
71
|
|
72
72
|
def to_hash
|
@@ -156,7 +156,7 @@ describe Signet::OAuth1::Credential, 'with a Hash for initialization' do
|
|
156
156
|
token = Signet::OAuth1::Credential.new(
|
157
157
|
"dpf43f3p2l4k3l03", "kd94hf93k423kf44"
|
158
158
|
)
|
159
|
-
parameters =
|
159
|
+
parameters = token.to_h
|
160
160
|
parameters['oauth_token'].should == "dpf43f3p2l4k3l03"
|
161
161
|
parameters['oauth_token_secret'].should == "kd94hf93k423kf44"
|
162
162
|
end
|
@@ -197,7 +197,8 @@ describe Signet::OAuth1::Client, 'configured for standard Google APIs' do
|
|
197
197
|
)
|
198
198
|
status, headers, body = response
|
199
199
|
status.should == 200
|
200
|
-
|
200
|
+
headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
|
201
|
+
headers['Content-Type'].should == 'application/json'
|
201
202
|
merge_body(body).should == '{"data":"goes here"}'
|
202
203
|
end
|
203
204
|
|
@@ -229,7 +230,8 @@ describe Signet::OAuth1::Client, 'configured for standard Google APIs' do
|
|
229
230
|
)
|
230
231
|
status, headers, body = response
|
231
232
|
status.should == 200
|
232
|
-
|
233
|
+
headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
|
234
|
+
headers['Content-Type'].should == 'application/json'
|
233
235
|
merge_body(body).should == '{"data":"goes here"}'
|
234
236
|
end
|
235
237
|
end
|
data/spec/signet/oauth_1_spec.rb
CHANGED
@@ -330,7 +330,7 @@ describe Signet::OAuth1 do
|
|
330
330
|
end
|
331
331
|
|
332
332
|
it 'should correctly parse an authorization header' do
|
333
|
-
parameters =
|
333
|
+
parameters = Signet::OAuth1.parse_authorization_header(
|
334
334
|
'OAuth realm="http://sp.example.com/", ' +
|
335
335
|
'oauth_consumer_key="0685bd9184jfhq22", ' +
|
336
336
|
'oauth_token="ad180jjd733klru7", ' +
|
@@ -339,7 +339,7 @@ describe Signet::OAuth1 do
|
|
339
339
|
'oauth_timestamp="137131200", ' +
|
340
340
|
'oauth_nonce="4572616e48616d6d65724c61686176", ' +
|
341
341
|
'oauth_version="1.0"'
|
342
|
-
)]
|
342
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
343
343
|
parameters['realm'].should == 'http://sp.example.com/'
|
344
344
|
parameters['oauth_consumer_key'].should == '0685bd9184jfhq22'
|
345
345
|
parameters['oauth_token'].should == 'ad180jjd733klru7'
|
@@ -464,14 +464,13 @@ describe Signet::OAuth1, 'when generating temporary credentials parameters' do
|
|
464
464
|
@signature_method = 'HMAC-SHA1'
|
465
465
|
@scope = 'http://photos.example.com/full_access'
|
466
466
|
@additional_parameters = [['scope', @scope]]
|
467
|
-
@unsigned_parameters =
|
467
|
+
@unsigned_parameters =
|
468
468
|
Signet::OAuth1.unsigned_temporary_credential_parameters(
|
469
469
|
:client_credential_key => @client_credential_key,
|
470
470
|
:callback => @callback,
|
471
471
|
:signature_method => @signature_method,
|
472
472
|
:additional_parameters => @additional_parameters
|
473
|
-
)
|
474
|
-
]
|
473
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
475
474
|
end
|
476
475
|
|
477
476
|
it 'should raise an error if the client credential key is missing' do
|
@@ -533,14 +532,13 @@ describe Signet::OAuth1, 'when generating token credential parameters' do
|
|
533
532
|
@temporary_credential_key = 'hh5s93j4hdidpola'
|
534
533
|
@verifier = '473f82d3'
|
535
534
|
@signature_method = 'HMAC-SHA1'
|
536
|
-
@unsigned_parameters =
|
535
|
+
@unsigned_parameters =
|
537
536
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
538
537
|
:client_credential_key => @client_credential_key,
|
539
538
|
:temporary_credential_key => @temporary_credential_key,
|
540
539
|
:signature_method => @signature_method,
|
541
540
|
:verifier => @verifier
|
542
|
-
)
|
543
|
-
]
|
541
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
544
542
|
end
|
545
543
|
|
546
544
|
it 'should raise an error if the client credential key is missing' do
|
@@ -623,13 +621,12 @@ describe Signet::OAuth1, 'when generating protected resource parameters' do
|
|
623
621
|
@client_credential_key = 'dpf43f3p2l4k3l03'
|
624
622
|
@token_credential_key = 'nnch734d00sl2jdk'
|
625
623
|
@signature_method = 'HMAC-SHA1'
|
626
|
-
@unsigned_parameters =
|
624
|
+
@unsigned_parameters =
|
627
625
|
Signet::OAuth1.unsigned_resource_parameters(
|
628
626
|
:client_credential_key => @client_credential_key,
|
629
627
|
:token_credential_key => @token_credential_key,
|
630
628
|
:signature_method => @signature_method
|
631
|
-
)
|
632
|
-
]
|
629
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
633
630
|
end
|
634
631
|
|
635
632
|
it 'should raise an error if the client credential key is missing' do
|
@@ -700,14 +697,13 @@ describe Signet::OAuth1, 'when generating token credential parameters ' +
|
|
700
697
|
)
|
701
698
|
@verifier = '473f82d3'
|
702
699
|
@signature_method = 'HMAC-SHA1'
|
703
|
-
@unsigned_parameters =
|
700
|
+
@unsigned_parameters =
|
704
701
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
705
702
|
:client_credential => @client_credential,
|
706
703
|
:temporary_credential => @temporary_credential,
|
707
704
|
:signature_method => @signature_method,
|
708
705
|
:verifier => @verifier
|
709
|
-
)
|
710
|
-
]
|
706
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
711
707
|
end
|
712
708
|
|
713
709
|
it 'should have the correct client credential key' do
|
@@ -759,13 +755,12 @@ describe Signet::OAuth1, 'when generating token credential parameters ' +
|
|
759
755
|
)
|
760
756
|
@verifier = '473f82d3'
|
761
757
|
@signature_method = 'HMAC-SHA1'
|
762
|
-
@unsigned_parameters =
|
758
|
+
@unsigned_parameters =
|
763
759
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
764
760
|
:client => @client,
|
765
761
|
:signature_method => @signature_method,
|
766
762
|
:verifier => @verifier
|
767
|
-
)
|
768
|
-
]
|
763
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
769
764
|
end
|
770
765
|
|
771
766
|
it 'should have the correct client credential key' do
|
@@ -818,14 +813,13 @@ describe Signet::OAuth1, 'when generating token credential parameters ' +
|
|
818
813
|
)
|
819
814
|
@verifier = '473f82d3'
|
820
815
|
@signature_method = 'HMAC-SHA1'
|
821
|
-
@unsigned_parameters =
|
816
|
+
@unsigned_parameters =
|
822
817
|
Signet::OAuth1.unsigned_token_credential_parameters(
|
823
818
|
:client_credential => @client_credential,
|
824
819
|
:temporary_credential => @temporary_credential,
|
825
820
|
:signature_method => @signature_method,
|
826
821
|
:verifier => @verifier
|
827
|
-
)
|
828
|
-
]
|
822
|
+
).inject({}) { |h,(k,v)| h[k]=v; h }
|
829
823
|
end
|
830
824
|
|
831
825
|
it 'should have the correct client credential key' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bob Aman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-13 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|