Skip to content

Instantly share code, notes, and snippets.

@rms1000watt
Created December 14, 2018 18:19
Show Gist options
  • Save rms1000watt/c51aa6b07308eb2ea57ada8dce5b1cdb to your computer and use it in GitHub Desktop.
Save rms1000watt/c51aa6b07308eb2ea57ada8dce5b1cdb to your computer and use it in GitHub Desktop.
github webhook secret hash hmac sha1 digest compare python lambda function through AWS API Gateway
import hmac
import hashlib
def equal_hash(event):
secret_value = "secret-value-put-in-github-webhook-ui"
sigExpected = str(event["headers"]["X-Hub-Signature"].replace("sha1=", ""))
sigCalculated = str(hmac.new(secret_value, event["body"], hashlib.sha1).hexdigest())
return hmac.compare_digest(sigCalculated, sigExpected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment