Class: Spree::Webhooks::EventSignature

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/webhooks/event_signature.rb

Instance Method Summary collapse

Constructor Details

#initialize(event, payload) ⇒ EventSignature

Returns a new instance of EventSignature.



7
8
9
10
# File 'app/models/spree/webhooks/event_signature.rb', line 7

def initialize(event, payload)
  @event = event
  @payload = payload
end

Instance Method Details

#computed_signatureString

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.

Returns:

  • (String)

    The computed signature



19
20
21
22
23
24
# File 'app/models/spree/webhooks/event_signature.rb', line 19

def computed_signature
  @computed_signature ||=
    Base64.strict_encode64(
      OpenSSL::HMAC.digest('sha256', @event.subscriber.secret_key, payload)
    )
end