Class: MonoMerchant::WebhookValidator
- Inherits:
-
Object
- Object
- MonoMerchant::WebhookValidator
- Defined in:
- lib/mono-merchant/webhook_validator.rb
Instance Method Summary collapse
-
#initialize(request) ⇒ WebhookValidator
constructor
A new instance of WebhookValidator.
- #public_key ⇒ Object
-
#valid? ⇒ Boolean
Validate webhook data signature with public key.
Constructor Details
#initialize(request) ⇒ WebhookValidator
Returns a new instance of WebhookValidator.
4 5 6 7 |
# File 'lib/mono-merchant/webhook_validator.rb', line 4 def initialize(request) @request = request @webhook_data = @request.raw_post end |
Instance Method Details
#public_key ⇒ Object
9 10 11 |
# File 'lib/mono-merchant/webhook_validator.rb', line 9 def public_key Pubkey.get end |
#valid? ⇒ Boolean
Validate webhook data signature with public key
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mono-merchant/webhook_validator.rb', line 16 def valid? return false if @webhook_data.nil? return false if signature.nil? return false unless public_key openssl_ec = OpenSSL::PKey::EC.new(public_key) openssl_ec.check_key return true if openssl_ec.verify(digest, signature, @webhook_data) warn "Webhook isn't authorized. Might be wrong signature or inconsistent webhook data." false end |