Class: Ey::Hmac::Adapter::Rack
Constant Summary
AUTHORIZATION_REGEXP
Instance Attribute Summary
#accept_digests, #authorization_header, #options, #request, #service, #sign_with
Instance Method Summary
collapse
#authenticated!, #authenticated?, #authorization, #canonicalize, #signature
Constructor Details
#initialize(request, options) ⇒ Rack
Returns a new instance of Rack.
4
5
6
7
|
# File 'lib/ey-hmac/adapter/rack.rb', line 4
def initialize(request, options)
super
@request = request.is_a?(Hash) ? ::Rack::Request.new(request) : request
end
|
Instance Method Details
#authorization_signature ⇒ Object
60
61
62
|
# File 'lib/ey-hmac/adapter/rack.rb', line 60
def authorization_signature
request.env["HTTP_#{.to_s.upcase}"]
end
|
#body ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/ey-hmac/adapter/rack.rb', line 27
def body
if request.env["rack.input"]
request.env["rack.input"].rewind
body = request.env["rack.input"].read
request.env["rack.input"].rewind
body == "" ? nil : body
else nil
end
end
|
#content_digest ⇒ Object
17
18
19
|
# File 'lib/ey-hmac/adapter/rack.rb', line 17
def content_digest
request.env['HTTP_CONTENT_DIGEST']
end
|
#content_type ⇒ Object
13
14
15
|
# File 'lib/ey-hmac/adapter/rack.rb', line 13
def content_type
request.content_type
end
|
#date ⇒ Object
37
38
39
|
# File 'lib/ey-hmac/adapter/rack.rb', line 37
def date
request.env['HTTP_DATE']
end
|
#method ⇒ Object
9
10
11
|
# File 'lib/ey-hmac/adapter/rack.rb', line 9
def method
request.request_method.to_s.upcase
end
|
#path ⇒ Object
45
46
47
|
# File 'lib/ey-hmac/adapter/rack.rb', line 45
def path
request.path
end
|
#set_content_digest ⇒ Object
21
22
23
24
25
|
# File 'lib/ey-hmac/adapter/rack.rb', line 21
def set_content_digest
if body
request.env['HTTP_CONTENT_DIGEST'] = Digest::MD5.hexdigest(body)
end
end
|
#set_date ⇒ Object
41
42
43
|
# File 'lib/ey-hmac/adapter/rack.rb', line 41
def set_date
request.env['HTTP_DATE'] = Time.now.httpdate
end
|
#sign!(key_id, key_secret) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/ey-hmac/adapter/rack.rb', line 49
def sign!(key_id, key_secret)
set_date
set_content_digest
if options[:version]
request.env['HTTP_X_SIGNATURE_VERSION'] = options[:version]
end
request.env["HTTP_#{.to_s.upcase}"] = authorization(key_id, key_secret)
end
|