Module: SecureRequest

Defined in:
lib/secure_request.rb,
lib/secure_request/version.rb

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.delete(url, timeout = 60) ⇒ Object



13
14
15
# File 'lib/secure_request.rb', line 13

def self.delete(url, timeout = 60)
  HTTParty.delete url, headers: make_httparty_headers(url.strip, Time.now, timeout)
end

.get(url, timeout = 60) ⇒ Object



17
18
19
# File 'lib/secure_request.rb', line 17

def self.get(url, timeout = 60)
  HTTParty.get url, headers: make_httparty_headers(url.strip, Time.now, timeout)
end

.post(url, body, timeout = 60) ⇒ Object



5
6
7
# File 'lib/secure_request.rb', line 5

def self.post(url, body, timeout = 60)
  HTTParty.post url, body: body.strip, headers: make_httparty_headers(url.strip + body.strip, Time.now, timeout)
end

.put(url, body, timeout = 60) ⇒ Object



9
10
11
# File 'lib/secure_request.rb', line 9

def self.put(url, body, timeout = 60)
  HTTParty.put url, body: body.strip, headers: make_httparty_headers(url.strip + body.strip, Time.now, timeout)
end

.verify(request) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/secure_request.rb', line 21

def self.verify(request)
  http_s = request.env['HTTP_X_SECUREREQUEST_S']
  http_ts = request.env['HTTP_X_SECUREREQUEST_TS']
  http_to = request.env['HTTP_X_SECUREREQUEST_TO']

  return false unless http_s and http_ts and http_to

  signature = http_s.strip
  timestamp = Time.at http_ts.to_i
  timeout = http_to.to_i

  data = request.url.strip

  if request.body.size > 0
    request.body.rewind
    data += request.body.gets.strip
  end

  Signatron.verify data, timestamp, timeout, signature
end