Sha256: db0b942e9144fea33a42cc9e83dfe63317b26601b771a2e0fed0dc4f71dfc203
Contents?: true
Size: 864 Bytes
Versions: 16
Compression:
Stored size: 864 Bytes
Contents
require 'base64' require 'openssl' module Spree module Webhooks class EventSignature def initialize(event, payload) @event = event @payload = payload end # Generates a base64-encoded HMAC SHA256 signature for the payload of the event. # # By using the stringified payload, the signature is made tamper-proof as any # alterations of the data during transit will lead to an incorrect signature # comparison by the client. # # @return [String] The computed signature def computed_signature @computed_signature ||= Base64.strict_encode64( OpenSSL::HMAC.digest('sha256', @event.subscriber.secret_key, payload) ) end private def payload @payload.is_a?(String) ? @payload : @payload.to_json end end end end
Version data entries
16 entries across 16 versions & 1 rubygems