class ActionDispatch::Request

Public Instance Methods

hmac_api_id(auth_prefix='\w+') click to toggle source
# File lib/action-dispatch/request.rb, line 5
def hmac_api_id(auth_prefix='\w+')
  result = parse_hmac(auth_prefix)
  result && result[1]
end
hmac_valid?(api_secret, options={}) click to toggle source
# File lib/action-dispatch/request.rb, line 10
def hmac_valid?(api_secret, options={})
  options         = { timeout_seconds: 900, auth_prefix: '\w+' }.merge(options)
  timeout_seconds = options.delete :timeout_seconds
  auth_prefix     = options.delete :auth_prefix
  result          = parse_hmac(auth_prefix)
  result &&
      ((Time.now.utc - Time.httpdate(timestamp).utc < timeout_seconds) rescue false) &&
      result[2] == hmac_token(request_method, content_type, calculate_content_md5, url, timestamp, api_secret, options)
end

Private Instance Methods

authorization_header() click to toggle source
# File lib/action-dispatch/request.rb, line 38
def authorization_header
  find_header %w(AUTHORIZATION HTTP_AUTHORIZATION)
end
calculate_content_md5() click to toggle source
# File lib/action-dispatch/request.rb, line 26
def calculate_content_md5
  (post? || put? || patch?) ? Digest::MD5.base64digest(raw_post) : ''
end
content_type() click to toggle source
# File lib/action-dispatch/request.rb, line 30
def content_type
  find_header(%w(CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE))
end
find_header(keys) click to toggle source
# File lib/action-dispatch/request.rb, line 42
def find_header(keys)
  cap_env = Hash[env.each_pair { |k, v| [k.to_s.upcase, v] }]
  keys.each { |k| return cap_env[k] unless cap_env[k].blank? }
  ''
end
parse_hmac(auth_prefix) click to toggle source
# File lib/action-dispatch/request.rb, line 22
def parse_hmac(auth_prefix)
  Regexp.new("\\A#{auth_prefix} ([^:]+):(.+)\\Z").match(authorization_header)
end
timestamp() click to toggle source
# File lib/action-dispatch/request.rb, line 34
def timestamp
  find_header(%w(DATE HTTP_DATE))
end