signature 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+
11
+ script: bundle exec rspec spec
@@ -1,29 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- signature (0.1.2)
5
- ruby-hmac
4
+ signature (0.1.3)
6
5
 
7
6
  GEM
8
7
  remote: http://rubygems.org/
9
8
  specs:
10
- diff-lcs (1.1.2)
11
- rspec (2.0.1)
12
- rspec-core (~> 2.0.1)
13
- rspec-expectations (~> 2.0.1)
14
- rspec-mocks (~> 2.0.1)
15
- rspec-core (2.0.1)
16
- rspec-expectations (2.0.1)
17
- diff-lcs (>= 1.1.2)
18
- rspec-mocks (2.0.1)
19
- rspec-core (~> 2.0.1)
20
- rspec-expectations (~> 2.0.1)
21
- ruby-hmac (0.4.0)
9
+ diff-lcs (1.1.3)
10
+ rspec (2.9.0)
11
+ rspec-core (~> 2.9.0)
12
+ rspec-expectations (~> 2.9.0)
13
+ rspec-mocks (~> 2.9.0)
14
+ rspec-core (2.9.0)
15
+ rspec-expectations (2.9.1)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.9.0)
22
18
 
23
19
  PLATFORMS
24
20
  ruby
25
21
 
26
22
  DEPENDENCIES
27
- rspec (~> 2.0.0)
28
- ruby-hmac
23
+ rspec (~> 2.9.0)
29
24
  signature!
data/README.md CHANGED
@@ -1,47 +1,55 @@
1
1
  signature
2
2
  =========
3
3
 
4
+ [![Build Status](https://secure.travis-ci.org/mloughran/signature.png?branch=master)](http://travis-ci.org/mloughran/signature)
5
+
4
6
  Examples
5
7
  --------
6
8
 
7
9
  Client example
8
10
 
9
- params = {:some => 'parameters'}
10
- token = Signature::Token.new('my_key', 'my_secret')
11
- request = Signature::Request.new('POST', '/api/thing', params)
12
- auth_hash = request.sign(token)
13
- query_params = params.merge(auth_hash)
14
-
15
- HTTParty.post('http://myservice/api/thing', {
16
- :query => query_params
17
- })
11
+ ```ruby
12
+ params = {:some => 'parameters'}
13
+ token = Signature::Token.new('my_key', 'my_secret')
14
+ request = Signature::Request.new('POST', '/api/thing', params)
15
+ auth_hash = request.sign(token)
16
+ query_params = params.merge(auth_hash)
17
+
18
+ HTTParty.post('http://myservice/api/thing', {
19
+ :query => query_params
20
+ })
21
+ ```
18
22
 
19
23
  `query_params` looks like:
20
24
 
21
- {
22
- :some => "parameters",
23
- :auth_timestamp => 1273231888,
24
- :auth_signature => "28b6bb0f242f71064916fad6ae463fe91f5adc302222dfc02c348ae1941eaf80",
25
- :auth_version => "1.0",
26
- :auth_key => "my_key"
27
- }
25
+ ```ruby
26
+ {
27
+ :some => "parameters",
28
+ :auth_timestamp => 1273231888,
29
+ :auth_signature => "28b6bb0f242f71064916fad6ae463fe91f5adc302222dfc02c348ae1941eaf80",
30
+ :auth_version => "1.0",
31
+ :auth_key => "my_key"
32
+ }
28
33
 
34
+ ```
29
35
  Server example (sinatra)
30
36
 
31
- error Signature::AuthenticationError do |controller|
32
- error = controller.env["sinatra.error"]
33
- halt 401, "401 UNAUTHORIZED: #{error.message}\n"
34
- end
37
+ ```ruby
38
+ error Signature::AuthenticationError do |controller|
39
+ error = controller.env["sinatra.error"]
40
+ halt 401, "401 UNAUTHORIZED: #{error.message}\n"
41
+ end
35
42
 
36
- post '/api/thing' do
37
- request = Authentication::Request.new('POST', env["REQUEST_PATH"], params)
38
- # This will raise a Signature::AuthenticationError if request does not authenticate
39
- token = request.authenticate do |key|
40
- Signature::Token.new(key, lookup_secret(key))
41
- end
43
+ post '/api/thing' do
44
+ request = Signature::Request.new('POST', env["REQUEST_PATH"], params)
45
+ # This will raise a Signature::AuthenticationError if request does not authenticate
46
+ token = request.authenticate do |key|
47
+ Signature::Token.new(key, lookup_secret(key))
48
+ end
42
49
 
43
- # Do whatever you need to do
44
- end
50
+ # Do whatever you need to do
51
+ end
52
+ ```
45
53
 
46
54
  Developing
47
55
  ----------
@@ -49,6 +57,8 @@ Developing
49
57
  bundle
50
58
  bundle exec rspec spec/*_spec.rb
51
59
 
60
+ Please see the travis status for a list of rubies tested against
61
+
52
62
  Copyright
53
63
  ---------
54
64
 
@@ -1,4 +1,4 @@
1
- require 'hmac-sha2'
1
+ require 'openssl'
2
2
 
3
3
  module Signature
4
4
  class AuthenticationError < RuntimeError; end
@@ -90,7 +90,8 @@ module Signature
90
90
  private
91
91
 
92
92
  def signature(token)
93
- HMAC::SHA256.hexdigest(token.secret, string_to_sign)
93
+ digest = OpenSSL::Digest::SHA256.new
94
+ OpenSSL::HMAC.hexdigest(digest, token.secret, string_to_sign)
94
95
  end
95
96
 
96
97
  def string_to_sign
@@ -1,3 +1,3 @@
1
1
  module Signature
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -17,6 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "ruby-hmac"
21
- s.add_development_dependency "rspec", "~> 2.0.0"
20
+ s.add_dependency "jruby-openssl" if defined?(JRUBY_VERSION)
21
+ s.add_development_dependency "rspec", "~> 2.9.0"
22
22
  end
metadata CHANGED
@@ -1,60 +1,37 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: signature
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 2
9
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Martyn Loughran
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-10-29 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: ruby-hmac
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :runtime
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
33
15
  name: rspec
34
- prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
16
+ requirement: &70163026801480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
37
19
  - - ~>
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 2
41
- - 0
42
- - 0
43
- version: 2.0.0
20
+ - !ruby/object:Gem::Version
21
+ version: 2.9.0
44
22
  type: :development
45
- version_requirements: *id002
23
+ prerelease: false
24
+ version_requirements: *70163026801480
46
25
  description: Simple key/secret based authentication for apis
47
- email:
26
+ email:
48
27
  - me@mloughran.com
49
28
  executables: []
50
-
51
29
  extensions: []
52
-
53
30
  extra_rdoc_files: []
54
-
55
- files:
31
+ files:
56
32
  - .document
57
33
  - .gitignore
34
+ - .travis.yml
58
35
  - Gemfile
59
36
  - Gemfile.lock
60
37
  - LICENSE
@@ -66,36 +43,31 @@ files:
66
43
  - signature.gemspec
67
44
  - spec/signature_spec.rb
68
45
  - spec/spec_helper.rb
69
- has_rdoc: true
70
46
  homepage: http://github.com/mloughran/signature
71
47
  licenses: []
72
-
73
48
  post_install_message:
74
49
  rdoc_options: []
75
-
76
- require_paths:
50
+ require_paths:
77
51
  - lib
78
- required_ruby_version: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- segments:
90
- - 0
91
- version: "0"
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
92
64
  requirements: []
93
-
94
65
  rubyforge_project:
95
- rubygems_version: 1.3.6
66
+ rubygems_version: 1.8.10
96
67
  signing_key:
97
68
  specification_version: 3
98
69
  summary: Simple key/secret based authentication for apis
99
- test_files:
70
+ test_files:
100
71
  - spec/signature_spec.rb
101
72
  - spec/spec_helper.rb
73
+ has_rdoc: