Module: CrashLog::AuthHMAC::Headers

Included in:
CrashLog::AuthHMAC, CanonicalString
Defined in:
lib/crash_log/auth_hmac.rb

Overview

This module provides a HMAC Authentication method for HTTP requests. It should work with net/http request classes and CGIRequest classes and hence Rails.

It is loosely based on the Amazon Web Services Authentication mechanism but generalized to be useful to any application that requires HMAC based authentication. As a result of the generalization, it won’t work with AWS because it doesn’t support the Amazon extension headers.

References

Cryptographic Hash functions

en.wikipedia.org/wiki/Cryptographic_hash_function

SHA-1 Hash function

en.wikipedia.org/wiki/SHA-1

HMAC algorithm

en.wikipedia.org/wiki/HMAC

RFC 2104

tools.ietf.org/html/rfc2104

Instance Method Summary collapse

Instance Method Details

#find_header(keys, headers) ⇒ Object



38
39
40
41
42
# File 'lib/crash_log/auth_hmac.rb', line 38

def find_header(keys, headers)
  keys.map do |key|
    headers[key]
  end.compact.first
end

#headers(request) ⇒ Object

Gets the headers for a request.

Attempts to deal with known HTTP header representations in Ruby. Currently handles net/http and Rails.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/crash_log/auth_hmac.rb', line 26

def headers(request)
  if request.respond_to?(:headers)
    request.headers
  elsif request.is_a?(Hash) && request.has_key?(:request_headers)
    request[:request_headers]
  elsif request.respond_to?(:[])
    request
  else
    raise ArgumentError, "Don't know how to get the headers from #{request.inspect}"
  end
end