signauth 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -3
- data/lib/signauth/request.rb +11 -10
- data/lib/signauth/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Signauth
|
2
2
|
|
3
|
-
|
3
|
+
Signature authentication.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,9 +16,45 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install signauth
|
18
18
|
|
19
|
-
##
|
19
|
+
## Examples
|
20
20
|
|
21
|
-
|
21
|
+
Client example
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
credentials = Signauth::Credentials.new('my_key', 'my_secret')
|
25
|
+
http_method = "GET"
|
26
|
+
host = "localhost"
|
27
|
+
path = "/action"
|
28
|
+
params = { "some" => "param" }
|
29
|
+
sig_version = 1
|
30
|
+
|
31
|
+
req = Signauth::Request.new( http_method, host, path, params, sig_version)
|
32
|
+
req.add_authorization!(credentials)
|
33
|
+
|
34
|
+
p req.params # => {"some"=>"param", "access_key_id"=>"my_key", "signature_version"=>"1", "signature_method"=>"HMAC-SHA-256", "signature"=>"7JNcJhJuzcUAGj6azz2wslmqnVomhDIFXZzpXZR1nkI="}
|
35
|
+
|
36
|
+
HTTParty.get('http://localhost/action', { :query => req.params })
|
37
|
+
```
|
38
|
+
|
39
|
+
Server example (rails)
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
request; # ActionController::Request object
|
43
|
+
|
44
|
+
begin
|
45
|
+
access_key_id = request.query_parameters['access_key_id']
|
46
|
+
credentials = Signauth::Credentials.new(access_key_id, lookup_secret(access_key_id))
|
47
|
+
|
48
|
+
req = Signauth::Request.new(
|
49
|
+
request.request_method,
|
50
|
+
request.domain,
|
51
|
+
request.path,
|
52
|
+
request.query_parameters)
|
53
|
+
req.authenticate(credentials)
|
54
|
+
rescue => e
|
55
|
+
render :status => :unauthorized, :text => "401 UNAUTHORIZED: #{e.message}\n"
|
56
|
+
end
|
57
|
+
```
|
22
58
|
|
23
59
|
## Contributing
|
24
60
|
|
data/lib/signauth/request.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
module Signauth
|
2
2
|
class Request
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
attr_reader :method
|
5
|
+
attr_reader :host
|
6
|
+
attr_reader :path
|
7
|
+
attr_reader :params
|
8
8
|
|
9
|
-
def initialize(signature_version = 1)
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
9
|
+
def initialize(method, host, path, params, signature_version = 1)
|
10
|
+
sig_version = params['signature_version'] ||= signature_version
|
11
|
+
extend(Signature.const_get("Version#{sig_version}"))
|
12
|
+
@method = method
|
13
|
+
@host = host
|
14
|
+
@path = path
|
15
|
+
@params = params.dup
|
15
16
|
end
|
16
17
|
|
17
18
|
end
|
data/lib/signauth/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
segments:
|
84
84
|
- 0
|
85
|
-
hash: -
|
85
|
+
hash: -965159027
|
86
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
87
|
none: false
|
88
88
|
requirements:
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
segments:
|
93
93
|
- 0
|
94
|
-
hash: -
|
94
|
+
hash: -965159027
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
97
|
rubygems_version: 1.8.24
|