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_md5 ⇒ Object
- #canonical_string_with_http_method(override_method = nil) ⇒ Object
-
#canonical_string_without_http_method ⇒ Object
(also: #canonical_string)
Returns the canonical string computed from the request’s headers.
-
#initialize(request) ⇒ Headers
constructor
A new instance of Headers.
- #md5_mismatch? ⇒ Boolean
- #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) ⇒ Headers
Returns a new instance of Headers.
8 9 10 11 12 |
# File 'lib/api_auth/headers.rb', line 8 def initialize(request) @original_request = request @request = initialize_request_driver(request) true end |
Instance Method Details
#authorization_header ⇒ Object
Returns the authorization header from the request’s headers
82 83 84 |
# File 'lib/api_auth/headers.rb', line 82 def @request. end |
#calculate_md5 ⇒ Object
90 91 92 |
# File 'lib/api_auth/headers.rb', line 90 def calculate_md5 @request.populate_content_md5 if @request.content_md5.empty? end |
#canonical_string_with_http_method(override_method = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/api_auth/headers.rb', line 66 def canonical_string_with_http_method(override_method = nil) request_method = override_method || @request.http_method if request_method.nil? raise ArgumentError, "unable to determine the http method from the request, please supply an override" end [ request_method.upcase, @request.content_type, @request.content_md5, parse_uri(@request.request_uri), @request. ].join(",") end |
#canonical_string_without_http_method ⇒ Object Also known as: canonical_string
Returns the canonical string computed from the request’s headers
55 56 57 58 59 60 61 |
# File 'lib/api_auth/headers.rb', line 55 def canonical_string_without_http_method [ @request.content_type, @request.content_md5, parse_uri(@request.request_uri), @request. ].join(",") end |
#md5_mismatch? ⇒ Boolean
94 95 96 97 98 99 100 |
# File 'lib/api_auth/headers.rb', line 94 def md5_mismatch? if @request.content_md5.empty? false else @request.md5_mismatch? end end |
#set_date ⇒ Object
86 87 88 |
# File 'lib/api_auth/headers.rb', line 86 def set_date @request.set_date if @request..empty? 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.
107 108 109 |
# File 'lib/api_auth/headers.rb', line 107 def sign_header(header) @request.set_auth_header header end |
#timestamp ⇒ Object
Returns the request timestamp
50 51 52 |
# File 'lib/api_auth/headers.rb', line 50 def @request. end |