Skip to content

Instantly share code, notes, and snippets.

@milosev1c
Created December 16, 2022 12:47
Show Gist options
  • Save milosev1c/1608b5c01bb36fcd45f6c07c7471c44f to your computer and use it in GitHub Desktop.
Save milosev1c/1608b5c01bb36fcd45f6c07c7471c44f to your computer and use it in GitHub Desktop.
how to check telegram auth
def check_hash(body):
secret_key = sha256(os.environ.get("TG_TOKEN", "").encode()).digest()
hash_string = body.pop("hash")
data_string = [f"{key}={value}" for key, value in body.items()]
data_string = "\n".join(sorted(data_string))
return hmac.new(secret_key, data_string.encode(), sha256).hexdigest() == hash_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment