mirror of
https://github.com/czhu12/canine.git
synced 2026-01-04 10:40:54 -06:00
30 lines
883 B
Ruby
30 lines
883 B
Ruby
module InboundWebhooks
|
|
class GithubController < ApplicationController
|
|
before_action :verify_event
|
|
|
|
def create
|
|
# Save webhook to database
|
|
record = InboundWebhook.create(body: payload)
|
|
|
|
# Queue webhook for processing
|
|
InboundWebhooks::GithubJob.perform_later(record, current_user:)
|
|
|
|
# Tell service we received the webhook successfully
|
|
head :ok
|
|
end
|
|
|
|
private
|
|
|
|
def verify_event
|
|
payload = request.body.read
|
|
# TODO: Verify the event was sent from the service
|
|
# Render `head :bad_request` if verification fails
|
|
secret = ENV["OMNIAUTH_GITHUB_WEBHOOK_SECRET"]
|
|
signature = "sha256=" + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret, payload)
|
|
unless Rack::Utils.secure_compare(signature, request.headers["HTTP_X_HUB_SIGNATURE_256"])
|
|
head :bad_request
|
|
end
|
|
end
|
|
end
|
|
end
|