Created
January 26, 2024 05:27
-
-
Save Jaxmetalmax/5091bf6c62329583b4b31965efb4a78b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hmac | |
import hashlib | |
def get_secret(key, message): | |
hashed = hmac.new(key.encode('utf-8'), message, hashlib.sha256).hexdigest() | |
return hashed | |
def get_github_secret(key, message): | |
hashed = hmac.new(key.encode('utf-8'), message, hashlib.sha1).hexdigest() | |
return hashed | |
def validate_key(): | |
access_token = config('SECRET_TOKEN') | |
payloadbody = request._get_body_string() | |
#This process the payload and the access token to check if it's a valid request | |
access_hash = get_secret(access_token, payloadbody) | |
if request.get_header('X-Hub-Signature') == access_hash: | |
print("access granted") | |
else: | |
print("Invalid api key") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment