signature 0.1.0 → 0.1.1
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/README.md +18 -6
- data/VERSION +1 -1
- data/lib/signature.rb +2 -2
- data/signature.gemspec +58 -0
- data/spec/signature_spec.rb +1 -1
- metadata +4 -3
data/README.md
CHANGED
@@ -1,20 +1,31 @@
|
|
1
1
|
signature
|
2
|
-
|
2
|
+
=========
|
3
3
|
|
4
4
|
Examples
|
5
|
-
|
5
|
+
--------
|
6
6
|
|
7
7
|
Client example
|
8
8
|
|
9
9
|
params = {:some => 'parameters'}
|
10
|
-
token = Signature::Token.new(
|
11
|
-
request = Signature::Request.new('POST', '/api/thing, params)
|
10
|
+
token = Signature::Token.new('my_key', 'my_secret')
|
11
|
+
request = Signature::Request.new('POST', '/api/thing', params)
|
12
12
|
auth_hash = request.sign(token)
|
13
|
+
query_params = params.merge(auth_hash)
|
13
14
|
|
14
15
|
HTTParty.post('http://myservice/api/thing', {
|
15
|
-
:query =>
|
16
|
+
:query => query_params
|
16
17
|
})
|
17
18
|
|
19
|
+
`query_params` looks like:
|
20
|
+
|
21
|
+
{
|
22
|
+
:some => "parameters",
|
23
|
+
:auth_timestamp => 1273231888,
|
24
|
+
:auth_signature => "28b6bb0f242f71064916fad6ae463fe91f5adc302222dfc02c348ae1941eaf80",
|
25
|
+
:auth_version => "1.0",
|
26
|
+
:auth_key => "my_key"
|
27
|
+
}
|
28
|
+
|
18
29
|
Server example (sinatra)
|
19
30
|
|
20
31
|
error Signature::AuthenticationError do |controller|
|
@@ -24,6 +35,7 @@ Server example (sinatra)
|
|
24
35
|
|
25
36
|
post '/api/thing' do
|
26
37
|
request = Authentication::Request.new('POST', env["REQUEST_PATH"], params)
|
38
|
+
# This will raise a Signature::AuthenticationError if request does not authenticate
|
27
39
|
token = request.authenticate do |key|
|
28
40
|
Signature::Token.new(key, lookup_secret(key))
|
29
41
|
end
|
@@ -32,6 +44,6 @@ Server example (sinatra)
|
|
32
44
|
end
|
33
45
|
|
34
46
|
Copyright
|
35
|
-
|
47
|
+
---------
|
36
48
|
|
37
49
|
Copyright (c) 2010 Martyn Loughran. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/signature.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'hmac-sha2'
|
2
|
-
require 'base64'
|
3
2
|
|
4
3
|
module Signature
|
5
4
|
class AuthenticationError < RuntimeError; end
|
@@ -134,7 +133,8 @@ module Signature
|
|
134
133
|
def validate_signature!(token)
|
135
134
|
unless @auth_hash["auth_signature"] == signature(token)
|
136
135
|
raise AuthenticationError, "Invalid signature: you should have "\
|
137
|
-
"sent HmacSHA256Hex(#{string_to_sign.inspect}, your_secret_key)"
|
136
|
+
"sent HmacSHA256Hex(#{string_to_sign.inspect}, your_secret_key)"\
|
137
|
+
", but you sent #{@auth_hash["auth_signature"].inspect}"
|
138
138
|
end
|
139
139
|
return true
|
140
140
|
end
|
data/signature.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{signature}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Martyn Loughran"]
|
12
|
+
s.date = %q{2010-07-20}
|
13
|
+
s.description = %q{Simple key/secret based authentication for apis}
|
14
|
+
s.email = %q{me@mloughran.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/signature.rb",
|
27
|
+
"signature.gemspec",
|
28
|
+
"spec/signature_spec.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/mloughran/signature}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
36
|
+
s.summary = %q{Simple key/secret based authentication for apis}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/signature_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<ruby-hmac>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<ruby-hmac>, [">= 0"])
|
51
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<ruby-hmac>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/spec/signature_spec.rb
CHANGED
@@ -88,7 +88,7 @@ describe Signature do
|
|
88
88
|
request = Signature::Request.new('POST', '/some/path', @params)
|
89
89
|
lambda {
|
90
90
|
request.authenticate_by_token!(@token)
|
91
|
-
}.should raise_error('Invalid signature: you should have sent HmacSHA256Hex("POST\n/some/path\nauth_key=key&auth_timestamp=1234&auth_version=1.0&go=here&query=params", your_secret_key)')
|
91
|
+
}.should raise_error('Invalid signature: you should have sent HmacSHA256Hex("POST\n/some/path\nauth_key=key&auth_timestamp=1234&auth_version=1.0&go=here&query=params", your_secret_key), but you sent "asdf"')
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should raise error if timestamp not available" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Martyn Loughran
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-20 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- Rakefile
|
61
61
|
- VERSION
|
62
62
|
- lib/signature.rb
|
63
|
+
- signature.gemspec
|
63
64
|
- spec/signature_spec.rb
|
64
65
|
- spec/spec.opts
|
65
66
|
- spec/spec_helper.rb
|