A Flask view decorator to verify Github's webhook signatures
Project description
flask-github-signature
A Flask view decorator to verify Github's webhook signatures.
Installation
Using pip
To get the latest version from pypi.org:
pip install flask-github-signature
Usage
export GH_WEBHOOK_SECRET="xyz"
# app.py
from flask import Flask
from flask_github_signature import verify_signature
app = Flask(__name__)
@app.route("/webhook", methods=["POST"])
@verify_signature
def webhook():
return "Payload signature verified."
run the previous Flask app with:
flask run
and test it with:
curl --request POST \
--header "X-Hub-Signature-256: sha256=eba50596a17c2c8fbdbc5c68223422fe41d5310bea51ffdc461430bce0386c54" \
--header "Content-Type: application/json" \
--data '{}' \
http://localhost:5000/webhook
Signing a test payload
If you want to test with another payload you can generate a signature using:
>>> import os
>>> from flask_github_signature import compute_signature
>>>
>>> secret = os.environ["GH_WEBHOOK_SECRET"]
>>> compute_signature(secret, b'{"message": "An example"}')
'04886433fda851ca66181cecbd9c283ba677468ba361b0a0a7ba57a867102b46'
>>>
when using a signature on a header don't forget to append sha256=
to it.
Testing
If you want to test, play or contribute to this repo:
git clone git@github.com:pabluk/flask-github-signature.git
cd flask-github-signature/
pip install -r requirements.txt
pip install -r requirements-dev.txt
pytest -v
black --line-length=127 tests/ flask_github_signature/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flask-github-signature-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | abe1f51ca6d7a610dd31eedf55becdad3deb698ed79796aa3f18a39202406a01 |
|
MD5 | f1ca1531db91ab765e2778733a0827ad |
|
BLAKE2b-256 | 9ecc129bc00c04d08533e3ff6bdf25bd959ac936726aca58cec7a2a14e3c98c4 |
Close
Hashes for flask_github_signature-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61b110ec0ddd73d9c8f09ba45dc1a82045fc7ac174ccc25528b12997c7863bb8 |
|
MD5 | 4f7992fcaf3f33458d426b67c43a174b |
|
BLAKE2b-256 | f30c26166f151c47e9ddb96a30348a3cd67ecaa5fbc71603bbffd8daa408893a |