Skip to content

Instantly share code, notes, and snippets.

@manuelep
Last active April 1, 2020 13:00
Show Gist options
  • Select an option

  • Save manuelep/4b64492ceeaa07f095302f94956ea554 to your computer and use it in GitHub Desktop.

Select an option

Save manuelep/4b64492ceeaa07f095302f94956ea554 to your computer and use it in GitHub Desktop.
authenticate woocommerce webhook
def compute(body):
secret = '<here is my secret key>'
dig = hmac.new(secret.encode(),
msg = body.encode(),
digestmod = hashlib.sha256
).digest()
computed = base64.b64encode(dig).decode()
return computed
def hookCheck(func):
def wrapper(*args, **kw):
signature = request.env.http_x_wc_webhook_signature
body = request.body.read() # ??
computed = compute(body)
if signature==computed:
return func(*args, **kw)
raise HTTP(403)
return wrapper
@service.json
def listenToHooks():
@hookCheck
def _main_():
# do stuff
return {}
return _main_()
@pythrick
Copy link
Copy Markdown

Thank you man for putting it on GH. It truly help me a lot today =]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment