craigderington / flask-rest-mailgun-webhooks

Catch MailGun WebHooks with Python3 + Flask + SQLAlchemy + Hashlib Signature Verification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Catch MailGun WebHooks with Python3 + SQLAlchemy + Webhook Signature Verification

API Routes:

{
  "clicks": "/api/v1/wh/mg/lead/email/click", 
  "delivered": "/api/v1/wh/mg/lead/email/delivered", 
  "dropped": "/api/v1/wh/mg/lead/email/dropped", 
  "hard-bounce": "/api/v1/wh/mg/lead/email/bounced", 
  "opens": "/api/v1/wh/mg/lead/email/open", 
  "spam-complaint": "/api/v1.0/wh/mg/lead/email/spam/complaint", 
  "unsubscribe": "/api/v1.0/wh/mg/lead/email/unsubscribe"
}

Signature Verification:

def verify(api_key, token, timestamp, signature):
    hmac_digest = hmac.new(key=mailgun_api_key,
                           msg='{}{}'.format(timestamp, token).encode('utf-8'),
                           digestmod=hashlib.sha256).hexdigest()
    return hmac.compare_digest(signature, hmac_digest)

About

Catch MailGun WebHooks with Python3 + Flask + SQLAlchemy + Hashlib Signature Verification


Languages

Language:Python 80.8%Language:HTML 19.2%