Class: ApiAuth::RequestDrivers::RackRequest
- Inherits:
-
Object
- Object
- ApiAuth::RequestDrivers::RackRequest
show all
- Includes:
- Helpers
- Defined in:
- lib/api_auth/request_drivers/rack.rb
Overview
Instance Method Summary
collapse
Methods included from Helpers
#b64_encode, #capitalize_keys, #sha256_base64digest
Constructor Details
#initialize(request) ⇒ RackRequest
Returns a new instance of RackRequest.
6
7
8
9
10
|
# File 'lib/api_auth/request_drivers/rack.rb', line 6
def initialize(request)
@request = request
true
end
|
Instance Method Details
76
77
78
|
# File 'lib/api_auth/request_drivers/rack.rb', line 76
def
%w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end
|
#calculated_hash ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/api_auth/request_drivers/rack.rb', line 18
def calculated_hash
if @request.body
body = @request.body.read
@request.body.rewind
else
body = ''
end
sha256_base64digest(body)
end
|
#content_hash ⇒ Object
55
56
57
|
# File 'lib/api_auth/request_drivers/rack.rb', line 55
def content_hash
(%w[X-AUTHORIZATION-CONTENT-SHA256])
end
|
#content_hash_mismatch? ⇒ Boolean
35
36
37
38
39
40
41
|
# File 'lib/api_auth/request_drivers/rack.rb', line 35
def content_hash_mismatch?
if %w[POST PUT].include?(@request.request_method)
calculated_hash != content_hash
else
false
end
end
|
#content_type ⇒ Object
51
52
53
|
# File 'lib/api_auth/request_drivers/rack.rb', line 51
def content_type
(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE])
end
|
43
44
45
|
# File 'lib/api_auth/request_drivers/rack.rb', line 43
def
@headers = capitalize_keys @request.env
end
|
#http_method ⇒ Object
47
48
49
|
# File 'lib/api_auth/request_drivers/rack.rb', line 47
def http_method
@request.request_method.upcase
end
|
#original_uri ⇒ Object
59
60
61
|
# File 'lib/api_auth/request_drivers/rack.rb', line 59
def original_uri
(%w[X-ORIGINAL-URI X_ORIGINAL_URI HTTP_X_ORIGINAL_URI])
end
|
#populate_content_hash ⇒ Object
28
29
30
31
32
33
|
# File 'lib/api_auth/request_drivers/rack.rb', line 28
def populate_content_hash
return unless %w[POST PUT].include?(@request.request_method)
@request.env['X-Authorization-Content-SHA256'] = calculated_hash
end
|
#request_uri ⇒ Object
63
64
65
|
# File 'lib/api_auth/request_drivers/rack.rb', line 63
def request_uri
@request.fullpath
end
|
12
13
14
15
16
|
# File 'lib/api_auth/request_drivers/rack.rb', line 12
def ()
@request.env['Authorization'] =
@request
end
|
#set_date ⇒ Object
67
68
69
70
|
# File 'lib/api_auth/request_drivers/rack.rb', line 67
def set_date
@request.env['DATE'] = Time.now.utc.httpdate
end
|
#timestamp ⇒ Object
72
73
74
|
# File 'lib/api_auth/request_drivers/rack.rb', line 72
def timestamp
(%w[DATE HTTP_DATE])
end
|