class SpecialDelivery::Authenticator

Attributes

event_params[R]

Public Class Methods

new(event_params) click to toggle source
# File lib/special_delivery/authenticator.rb, line 3
def initialize(event_params)
  @event_params = event_params.to_hash
end

Public Instance Methods

authentic?() click to toggle source
# File lib/special_delivery/authenticator.rb, line 7
def authentic?
  actual_signature == expected_signature
rescue
  false
end

Private Instance Methods

actual_signature() click to toggle source
# File lib/special_delivery/authenticator.rb, line 33
def actual_signature
  event_params.fetch('signature')
end
api_key() click to toggle source
# File lib/special_delivery/authenticator.rb, line 21
def api_key
  MAILGUN_CONFIG[:api_key]
end
expected_signature() click to toggle source
# File lib/special_delivery/authenticator.rb, line 17
def expected_signature
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), api_key,"#{timestamp}#{token}")
end
timestamp() click to toggle source
# File lib/special_delivery/authenticator.rb, line 25
def timestamp
  event_params.fetch('timestamp')
end
token() click to toggle source
# File lib/special_delivery/authenticator.rb, line 29
def token
  event_params.fetch('token')
end