Class: ApiAuth::RequestDrivers::ActionControllerRequest

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/api_auth/request_drivers/action_controller.rb

Overview

:nodoc:

Direct Known Subclasses

ActionDispatchRequest

Instance Method Summary collapse

Methods included from Helpers

#b64_encode, #capitalize_keys, #md5_base64digest

Constructor Details

#initialize(request) ⇒ ActionControllerRequest

Returns a new instance of ActionControllerRequest.



6
7
8
9
10
# File 'lib/api_auth/request_drivers/action_controller.rb', line 6

def initialize(request)
  @request = request
  fetch_headers
  true
end

Instance Method Details

#authorization_headerObject



70
71
72
# File 'lib/api_auth/request_drivers/action_controller.rb', line 70

def authorization_header
  find_header %w(Authorization AUTHORIZATION HTTP_AUTHORIZATION)
end

#calculated_md5Object



18
19
20
21
# File 'lib/api_auth/request_drivers/action_controller.rb', line 18

def calculated_md5
  body = @request.raw_post
  md5_base64digest(body)
end

#content_md5Object



51
52
53
54
# File 'lib/api_auth/request_drivers/action_controller.rb', line 51

def content_md5
  value = find_header(%w(CONTENT-MD5 CONTENT_MD5 HTTP_CONTENT_MD5))
  value.nil? ? '' : value
end

#content_typeObject



46
47
48
49
# File 'lib/api_auth/request_drivers/action_controller.rb', line 46

def content_type
  value = find_header(%w(CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE))
  value.nil? ? '' : value
end

#fetch_headersObject



38
39
40
# File 'lib/api_auth/request_drivers/action_controller.rb', line 38

def fetch_headers
  @headers = capitalize_keys @request.env
end

#http_methodObject



42
43
44
# File 'lib/api_auth/request_drivers/action_controller.rb', line 42

def http_method
  @request.request_method.to_s.upcase
end

#md5_mismatch?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/api_auth/request_drivers/action_controller.rb', line 30

def md5_mismatch?
  if @request.put? || @request.post?
    calculated_md5 != content_md5
  else
    false
  end
end

#populate_content_md5Object



23
24
25
26
27
28
# File 'lib/api_auth/request_drivers/action_controller.rb', line 23

def populate_content_md5
  if @request.put? || @request.post?
    @request.env['Content-MD5'] = calculated_md5
    fetch_headers
  end
end

#request_uriObject



56
57
58
# File 'lib/api_auth/request_drivers/action_controller.rb', line 56

def request_uri
  @request.request_uri
end

#set_auth_header(header) ⇒ Object



12
13
14
15
16
# File 'lib/api_auth/request_drivers/action_controller.rb', line 12

def set_auth_header(header)
  @request.env['Authorization'] = header
  fetch_headers
  @request
end

#set_dateObject



60
61
62
63
# File 'lib/api_auth/request_drivers/action_controller.rb', line 60

def set_date
  @request.env['HTTP_DATE'] = Time.now.utc.httpdate
  fetch_headers
end

#timestampObject



65
66
67
68
# File 'lib/api_auth/request_drivers/action_controller.rb', line 65

def timestamp
  value = find_header(%w(DATE HTTP_DATE))
  value.nil? ? '' : value
end