Class: Nexmo::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo/signature.rb

Instance Method Summary collapse

Constructor Details

#initialize(secret) ⇒ Signature

Returns a new instance of Signature.


6
7
8
# File 'lib/nexmo/signature.rb', line 6

def initialize(secret)
  @secret = secret
end

Instance Method Details

#check(params) ⇒ Object

Check webhook request signature.

Examples:

client = Nexmo::Client.new(signature_secret: 'secret')

if client.signature.check(request.GET)
  # valid signature
else
  # invalid signature
end

Parameters:

  • params (Hash)

See Also:


25
26
27
28
29
30
31
# File 'lib/nexmo/signature.rb', line 25

def check(params)
  params = params.dup

  signature = params.delete('sig')

  ::JWT::SecurityUtils.secure_compare(signature, digest(params))
end