Module: Philiprehberger::WebhookSignature
- Defined in:
- lib/philiprehberger/webhook_signature.rb,
lib/philiprehberger/webhook_signature/signer.rb,
lib/philiprehberger/webhook_signature/version.rb,
lib/philiprehberger/webhook_signature/verifier.rb
Defined Under Namespace
Classes: Error, Signer, VerificationError, Verifier
Constant Summary collapse
- VERSION =
'0.4.0'
Class Method Summary collapse
-
.sign(payload, secret:, timestamp: Time.now.to_i, algorithm: :sha256) ⇒ Hash
Convenience: sign a payload.
-
.verify(payload, timestamp:, signature:, secret: nil, secrets: nil, tolerance: 300, algorithm: :sha256) ⇒ Boolean
Convenience: verify a payload.
Class Method Details
.sign(payload, secret:, timestamp: Time.now.to_i, algorithm: :sha256) ⇒ Hash
Convenience: sign a payload.
21 22 23 |
# File 'lib/philiprehberger/webhook_signature.rb', line 21 def self.sign(payload, secret:, timestamp: Time.now.to_i, algorithm: :sha256) Signer.new(secret, algorithm: algorithm).sign(payload, timestamp: ) end |
.verify(payload, timestamp:, signature:, secret: nil, secrets: nil, tolerance: 300, algorithm: :sha256) ⇒ Boolean
Convenience: verify a payload.
35 36 37 38 39 40 41 42 |
# File 'lib/philiprehberger/webhook_signature.rb', line 35 def self.verify(payload, timestamp:, signature:, secret: nil, secrets: nil, tolerance: 300, algorithm: :sha256) raise ArgumentError, 'Provide either secret: or secrets:, not both' if !secret.nil? && !secrets.nil? raise ArgumentError, 'Must provide secret: or secrets:' if secret.nil? && secrets.nil? list = secrets.nil? ? [secret] : secrets Verifier.new(secrets: list, algorithm: algorithm) .verify(payload, timestamp: , signature: signature, tolerance: tolerance) end |