signature 0.1.2 → 0.1.3
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.
- data/.travis.yml +11 -0
- data/Gemfile.lock +11 -16
- data/README.md +38 -28
- data/lib/signature.rb +3 -2
- data/lib/signature/version.rb +1 -1
- data/signature.gemspec +2 -2
- metadata +34 -62
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,29 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
signature (0.1.
|
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.
|
11
|
-
rspec (2.0
|
12
|
-
rspec-core (~> 2.0
|
13
|
-
rspec-expectations (~> 2.0
|
14
|
-
rspec-mocks (~> 2.0
|
15
|
-
rspec-core (2.0
|
16
|
-
rspec-expectations (2.
|
17
|
-
diff-lcs (
|
18
|
-
rspec-mocks (2.0
|
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.
|
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
|
+
[](http://travis-ci.org/mloughran/signature)
|
5
|
+
|
4
6
|
Examples
|
5
7
|
--------
|
6
8
|
|
7
9
|
Client example
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
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
|
|
data/lib/signature.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
-
|
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
|
data/lib/signature/version.rb
CHANGED
data/signature.gemspec
CHANGED
@@ -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 "
|
21
|
-
s.add_development_dependency "rspec", "~> 2.
|
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
|
-
|
5
|
-
|
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
|
-
|
18
|
-
|
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
|
-
|
35
|
-
|
36
|
-
requirements:
|
16
|
+
requirement: &70163026801480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
37
19
|
- - ~>
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
|
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
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
|
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.
|
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:
|