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