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

Constructor Details

#initialize(request) ⇒ ActionControllerRequest

Returns a new instance of ActionControllerRequest.


9
10
11
12
13
# File 'lib/api_auth/request_drivers/action_controller.rb', line 9

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

Instance Method Details

#authorization_headerObject


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

def authorization_header
  find_header %w(Authorization AUTHORIZATION HTTP_AUTHORIZATION)
end

#calculated_md5Object


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

def calculated_md5
  if @request.body
    body = @request.raw_post
  else
    body = ''
  end
  Digest::MD5.base64digest(body)
end

#content_md5Object


53
54
55
56
# File 'lib/api_auth/request_drivers/action_controller.rb', line 53

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

#content_typeObject


48
49
50
51
# File 'lib/api_auth/request_drivers/action_controller.rb', line 48

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

#fetch_headersObject


44
45
46
# File 'lib/api_auth/request_drivers/action_controller.rb', line 44

def fetch_headers
  capitalize_keys @request.env
end

#md5_mismatch?Boolean

Returns:

  • (Boolean)

36
37
38
39
40
41
42
# File 'lib/api_auth/request_drivers/action_controller.rb', line 36

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

#populate_content_md5Object


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

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

#request_uriObject


58
59
60
# File 'lib/api_auth/request_drivers/action_controller.rb', line 58

def request_uri
  @request.request_uri
end

#set_auth_header(header) ⇒ Object


15
16
17
18
19
# File 'lib/api_auth/request_drivers/action_controller.rb', line 15

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

#set_dateObject


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

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

#timestampObject


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

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