Class: Mailgun::Secure

Inherits:
Object show all
Defined in:
lib/mailgun/secure.rb

Instance Method Summary collapse

Constructor Details

#initialize(mailgun) ⇒ Secure

Returns a new instance of Secure.



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

def initialize(mailgun)
  @mailgun = mailgun
end

Instance Method Details

#check_request_auth(timestamp, token, signature, offset = -5)) ⇒ Object

check request auth



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mailgun/secure.rb', line 18

def check_request_auth(timestamp, token, signature, offset=-5)
  if offset != 0
    offset = Time.now.to_i + offset * 60
    return false if timestamp < offset
  end
  
  return signature == OpenSSL::HMAC.hexdigest(
    OpenSSL::Digest::Digest.new('sha256'),
    Mailgun.api_key,
    '%s%s' % [timestamp, token])
end