Class: EventSubEvents::SignatureVerifier
- Inherits:
-
Object
- Object
- EventSubEvents::SignatureVerifier
- Defined in:
- lib/event_sub_events/signature_verifier.rb
Instance Method Summary collapse
-
#initialize(request) ⇒ SignatureVerifier
constructor
A new instance of SignatureVerifier.
- #reconstruct_event ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(request) ⇒ SignatureVerifier
Returns a new instance of SignatureVerifier.
7 8 9 |
# File 'lib/event_sub_events/signature_verifier.rb', line 7 def initialize(request) @request = request end |
Instance Method Details
#reconstruct_event ⇒ Object
34 35 36 37 |
# File 'lib/event_sub_events/signature_verifier.rb', line 34 def reconstruct_event body = @request.body.read JSON.parse(body, object_class: OpenStruct) end |
#verify ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/event_sub_events/signature_verifier.rb', line 11 def verify request = @request = request.headers["Twitch-Eventsub-Message-Id"] = request.headers["Twitch-Eventsub-Message-Timestamp"] signature = request.headers["Twitch-Eventsub-Message-Signature"].gsub("sha256=", "") body = request.body.read = + + body secrets = EventSubEvents.signing_secrets if EventSubEvents.signing_secret secrets.each_with_index do |secret, i| begin hex = OpenSSL::HMAC.hexdigest('sha256', secret, ) return validate(hex, signature) rescue EventSubEvents::SignatureVerificationError raise if i == secrets.length - 1 next end end end |