Class: Vonage::Signature

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Signature

Returns a new instance of Signature.



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

def initialize(config)
  @config = config
end

Instance Method Details

#check(params, signature_secret: @config.signature_secret, signature_method: @config.signature_method) ⇒ Object

Check webhook request signature.

Examples:

client = Vonage::Client.new
client.config.signature_secret = 'secret'
client.config.signature_method = 'sha512'

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

Parameters:

  • params (Hash)

See Also:



30
31
32
33
34
35
36
# File 'lib/vonage/signature.rb', line 30

def check(params, signature_secret: @config.signature_secret, signature_method: @config.signature_method)
  params = params.dup

  signature = params.delete('sig')

  ::JWT::JWA::Hmac::SecurityUtils.secure_compare(signature, digest(params, signature_secret, signature_method))
end