hmac_signature 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +80 -17
  2. data/lib/hmac_signature/version.rb +1 -1
  3. metadata +1 -1
data/README.md CHANGED
@@ -1,29 +1,92 @@
1
- # HmacSignature
1
+ HmacSignature
2
+ =============
2
3
 
3
- TODO: Write a gem description
4
+ Credit to Martyn Loughran and the 'signature' gem, which HmacSignature is based on.
4
5
 
5
- ## Installation
6
+ Examples
7
+ --------
6
8
 
7
- Add this line to your application's Gemfile:
9
+ Client example (Sending auth via query_string/post body)
8
10
 
9
- gem 'hmac_signature'
11
+ ```ruby
12
+ params = {:some => 'parameters'}
13
+ token = HmacSignature::Token.new('my_key', 'my_secret')
14
+ request = HmacSignature::Strategy::Params::Request.new('POST', '/api/thing', params)
15
+ auth_hash = request.sign(token)
16
+ query_params = params.merge(auth_hash)
10
17
 
11
- And then execute:
18
+ HTTParty.post('http://myservice/api/thing', {
19
+ :query => query_params
20
+ })
21
+ ```
12
22
 
13
- $ bundle
23
+ `query_params` looks like:
14
24
 
15
- Or install it yourself as:
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
+ }
16
33
 
17
- $ gem install hmac_signature
34
+ ```
18
35
 
19
- ## Usage
36
+ Client example (Sending auth via headers)
20
37
 
21
- TODO: Write usage instructions here
38
+ ```ruby
39
+ params = {:some => 'parameters'}
40
+ token = HmacSignature::Token.new('my_key', 'my_secret')
41
+ request = HmacSignature::Strategy::Headers::Request.new('POST', '/api/thing', params)
42
+ auth_headers = request.sign(token)
22
43
 
23
- ## Contributing
44
+ HTTParty.post('http://myservice/api/thing', {
45
+ :query => params,
46
+ :headers => auth_headers
47
+ })
48
+ ```
24
49
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
50
+ `auth_headers` looks like:
51
+
52
+ ```ruby
53
+ {
54
+ 'X-Auth-Expires' => 1273231888,
55
+ 'X-Auth-Signature' => "28b6bb0f242f71064916fad6ae463fe91f5adc302222dfc02c348ae1941eaf80",
56
+ 'X-Auth-Version' => "1.0",
57
+ 'X-Auth-Key' => "my_key"
58
+ }
59
+
60
+ ```
61
+
62
+ Server example (sinatra)
63
+
64
+ ```ruby
65
+ error HmacSignature::AuthenticationError do |controller|
66
+ error = controller.env["sinatra.error"]
67
+ halt 401, "401 UNAUTHORIZED: #{error.message}\n"
68
+ end
69
+
70
+ post '/api/thing' do
71
+ request = HmacSignature::Strategy::Params::Request.new('POST', env["REQUEST_PATH"], params)
72
+ # This will raise a HmacSignature::AuthenticationError if request does not authenticate
73
+ token = request.authenticate do |key|
74
+ HmacSignature::Token.new(key, lookup_secret(key))
75
+ end
76
+
77
+ # Do whatever you need to do
78
+ end
79
+ ```
80
+
81
+ Developing
82
+ ----------
83
+
84
+ bundle
85
+ bundle exec rspec spec/*_spec.rb
86
+
87
+ Please see the travis status for a list of rubies tested against
88
+
89
+ Copyright
90
+ ---------
91
+
92
+ Copyright (c) 2013 Erik Lott. See LICENSE for details.
@@ -1,3 +1,3 @@
1
1
  module HmacSignature
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hmac_signature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: