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, #secure_compare, #signature
Constructor Details
#initialize(request, options) ⇒ Rack
Returns a new instance of Rack.
4
5
6
7
8
9
10
|
# File 'lib/ey-hmac/adapter/rack.rb', line 4
def initialize(request, options)
super
@request = if request.is_a?(Hash)
::Rack::Request.new(request)
else request
end
end
|
Instance Method Details
#authorization_signature ⇒ Object
54
55
56
|
# File 'lib/ey-hmac/adapter/rack.rb', line 54
def authorization_signature
request.env["HTTP_#{.to_s.upcase}"]
end
|
#body ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/ey-hmac/adapter/rack.rb', line 28
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
20
21
22
23
24
25
26
|
# File 'lib/ey-hmac/adapter/rack.rb', line 20
def content_digest
if existing = request.env['HTTP_CONTENT_DIGEST']
existing
elsif digest = body && Digest::MD5.hexdigest(body)
request.env['HTTP_CONTENT_DIGEST'] = digest
end
end
|
#content_type ⇒ Object
16
17
18
|
# File 'lib/ey-hmac/adapter/rack.rb', line 16
def content_type
request.content_type
end
|
#date ⇒ Object
38
39
40
|
# File 'lib/ey-hmac/adapter/rack.rb', line 38
def date
request.env['HTTP_DATE'] ||= Time.now.httpdate
end
|
#method ⇒ Object
12
13
14
|
# File 'lib/ey-hmac/adapter/rack.rb', line 12
def method
request.request_method.to_s.upcase
end
|
#path ⇒ Object
42
43
44
|
# File 'lib/ey-hmac/adapter/rack.rb', line 42
def path
request.path
end
|
#sign!(key_id, key_secret) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/ey-hmac/adapter/rack.rb', line 46
def sign!(key_id, key_secret)
if options[:version]
request.env['HTTP_X_SIGNATURE_VERSION'] = options[:version]
end
request.env["HTTP_#{.to_s.upcase}"] = authorization(key_id, key_secret)
end
|