Class: ApiAuth::RequestDrivers::FaradayRequest
- Inherits:
-
Object
- Object
- ApiAuth::RequestDrivers::FaradayRequest
show all
- Includes:
- Helpers
- Defined in:
- lib/api_auth/request_drivers/faraday.rb
Overview
Instance Method Summary
collapse
Methods included from Helpers
#b64_encode, #capitalize_keys, #sha256_base64digest
Constructor Details
Returns a new instance of FaradayRequest.
6
7
8
9
10
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 6
def initialize(request)
@request = request
true
end
|
Instance Method Details
74
75
76
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 74
def
%w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end
|
#calculated_hash ⇒ Object
18
19
20
21
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 18
def calculated_hash
body = @request.body || ''
sha256_base64digest(body)
end
|
#content_hash ⇒ Object
50
51
52
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 50
def content_hash
(%w[X-AUTHORIZATION-CONTENT-SHA256])
end
|
#content_hash_mismatch? ⇒ Boolean
30
31
32
33
34
35
36
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 30
def content_hash_mismatch?
if %w[POST PUT].include?(@request.http_method.to_s.upcase)
calculated_hash != content_hash
else
false
end
end
|
#content_type ⇒ Object
46
47
48
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 46
def content_type
(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE])
end
|
38
39
40
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 38
def
@headers = capitalize_keys @request.
end
|
#http_method ⇒ Object
42
43
44
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 42
def http_method
@request.http_method.to_s.upcase
end
|
#original_uri ⇒ Object
54
55
56
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 54
def original_uri
(%w[X-ORIGINAL-URI X_ORIGINAL_URI HTTP_X_ORIGINAL_URI])
end
|
#populate_content_hash ⇒ Object
23
24
25
26
27
28
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 23
def populate_content_hash
return unless %w[POST PUT].include?(@request.http_method.to_s.upcase)
@request.['X-Authorization-Content-SHA256'] = calculated_hash
end
|
#request_uri ⇒ Object
58
59
60
61
62
63
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 58
def request_uri
query_string = @request.params.to_query
query_string = nil if query_string.empty?
uri = URI::HTTP.new(nil, nil, nil, nil, nil, @request.path, nil, query_string, nil)
uri.to_s
end
|
12
13
14
15
16
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 12
def ()
@request.['Authorization'] =
@request
end
|
#set_date ⇒ Object
65
66
67
68
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 65
def set_date
@request.['DATE'] = Time.now.utc.httpdate
end
|
#timestamp ⇒ Object
70
71
72
|
# File 'lib/api_auth/request_drivers/faraday.rb', line 70
def timestamp
(%w[DATE HTTP_DATE])
end
|