Class: Signalwire::Webhook::ValidateRequest
- Inherits:
-
Object
- Object
- Signalwire::Webhook::ValidateRequest
- Defined in:
- lib/signalwire/webhook/validate_request.rb
Instance Attribute Summary collapse
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
Instance Method Summary collapse
-
#initialize(private_key) ⇒ ValidateRequest
constructor
A new instance of ValidateRequest.
- #validate(url, raw_body, header) ⇒ Object
Constructor Details
#initialize(private_key) ⇒ ValidateRequest
Returns a new instance of ValidateRequest.
9 10 11 12 |
# File 'lib/signalwire/webhook/validate_request.rb', line 9 def initialize(private_key) @private_key = private_key raise ArgumentError, 'Private key is required' if @private_key.nil? end |
Instance Attribute Details
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
7 8 9 |
# File 'lib/signalwire/webhook/validate_request.rb', line 7 def private_key @private_key end |
Instance Method Details
#validate(url, raw_body, header) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/signalwire/webhook/validate_request.rb', line 14 def validate(url, raw_body, header) return false if header.nil? || url.nil? # compatibility validation for POST parameters of x-www-form-urlencoded requests if raw_body.is_a?(Hash) return validate_with_compatibility_api(url, raw_body, header) end # relay json validation payload = url + raw_body expected_signature = compute_signature(payload) valid = secure_compare(expected_signature, header) return true if valid # fallback compatibilty json validation validate_with_compatibility_api(url, raw_body, header) end |