Class: Spree::Webhooks::EventSignature
- Inherits:
-
Object
- Object
- Spree::Webhooks::EventSignature
- Defined in:
- app/models/spree/webhooks/event_signature.rb
Instance Method Summary collapse
-
#computed_signature ⇒ String
Generates a base64-encoded HMAC SHA256 signature for the payload of the event.
-
#initialize(event, payload) ⇒ EventSignature
constructor
A new instance of EventSignature.
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_signature ⇒ String
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.
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 |