Skip to content

Instantly share code, notes, and snippets.

@Jaxmetalmax
Created January 26, 2024 05:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaxmetalmax/5091bf6c62329583b4b31965efb4a78b to your computer and use it in GitHub Desktop.
Save Jaxmetalmax/5091bf6c62329583b4b31965efb4a78b to your computer and use it in GitHub Desktop.
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