Skip to content

Instantly share code, notes, and snippets.

@omarryhan
Created January 3, 2019 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarryhan/e2bd8e78749ffe053f5a1717045c9bfb to your computer and use it in GitHub Desktop.
Save omarryhan/e2bd8e78749ffe053f5a1717045c9bfb to your computer and use it in GitHub Desktop.
Coinbase Commerce Python Validation
@coinbase_bp.route('/service/coinbase/hook', methods=['GET', 'POST', 'UPDATE', 'DELETE'], name='coinbase_hook', version=1)
async def webhook(request):
secret = request.app.config.COINBASE_WEBHOOK_SHARED_SECRET
payload = request.json
if not payload.get('event'):
return response.json(dict(
code=200, # We need coinbase to stop sending this message wether its valid or not
message='Invalid Event'
))
sig_header = request.headers.get('X-CC-Webhook-Signature', None)
if not sig_header:
return response.json(dict(
code=200,
message='Missing signature'
))
sig = hmac.new(
secret.encode(),
msg=payload.encode(),
digestmod=sha256
)
computed_sig = sig.hexdigest()
if computed_sig != sig_header:
return response.json(dict(
code=200,
message='Invalid signature'
))
else:
# process event
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment