Class: ApiAuth::Headers
- Inherits:
-
Object
- Object
- ApiAuth::Headers
- Includes:
- RequestDrivers
- Defined in:
- lib/api_auth/headers.rb
Overview
Builds the canonical string given a request object.
Instance Method Summary collapse
-
#authorization_header ⇒ Object
Returns the authorization header from the request’s headers.
- #calculate_hash ⇒ Object
- #canonical_string(override_method = nil, headers_to_sign = []) ⇒ Object
- #content_hash_mismatch? ⇒ Boolean
-
#initialize(request, authorize_md5: false) ⇒ Headers
constructor
A new instance of Headers.
- #set_date ⇒ Object
-
#sign_header(header) ⇒ Object
Sets the request’s authorization header with the passed in value.
-
#timestamp ⇒ Object
Returns the request timestamp.
Constructor Details
#initialize(request, authorize_md5: false) ⇒ Headers
Returns a new instance of Headers.
6 7 8 9 10 |
# File 'lib/api_auth/headers.rb', line 6 def initialize(request, authorize_md5: false) @original_request = request @request = initialize_request_driver(request, authorize_md5: ) true end |
Instance Method Details
#authorization_header ⇒ Object
Returns the authorization header from the request’s headers
78 79 80 |
# File 'lib/api_auth/headers.rb', line 78 def @request. end |
#calculate_hash ⇒ Object
86 87 88 |
# File 'lib/api_auth/headers.rb', line 86 def calculate_hash @request.populate_content_hash if @request.content_hash.nil? end |
#canonical_string(override_method = nil, headers_to_sign = []) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/api_auth/headers.rb', line 57 def canonical_string(override_method = nil, headers_to_sign = []) request_method = override_method || @request.http_method raise ArgumentError, 'unable to determine the http method from the request, please supply an override' if request_method.nil? headers = @request.fetch_headers canonical_array = [request_method.upcase, @request.content_type, @request.content_hash, parse_uri(@request.original_uri || @request.request_uri), @request.] if headers_to_sign.is_a?(Array) && headers_to_sign.any? headers_to_sign.each { |h| canonical_array << headers[h] if headers[h].present? } end canonical_array.join(',') end |
#content_hash_mismatch? ⇒ Boolean
90 91 92 93 94 95 96 |
# File 'lib/api_auth/headers.rb', line 90 def content_hash_mismatch? if @request.content_hash.nil? false else @request.content_hash_mismatch? end end |
#set_date ⇒ Object
82 83 84 |
# File 'lib/api_auth/headers.rb', line 82 def set_date @request.set_date if @request..nil? end |
#sign_header(header) ⇒ Object
Sets the request’s authorization header with the passed in value. The header should be the ApiAuth HMAC signature.
This will return the original request object with the signed Authorization header already in place.
103 104 105 |
# File 'lib/api_auth/headers.rb', line 103 def sign_header(header) @request.set_auth_header header end |
#timestamp ⇒ Object
Returns the request timestamp
53 54 55 |
# File 'lib/api_auth/headers.rb', line 53 def @request. end |