-
-
Save Forevka/7a1c72eb7b26e7c961e0a034d54d2766 to your computer and use it in GitHub Desktop.
telegram site auth
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
# implementation of Telegram site authorization checking algorithm | |
# for more information https://core.telegram.org/widgets/login#checking-authorization | |
import collections | |
import hmac | |
import hashlib | |
def check_string(data, token): | |
secret = hashlib.sha256() | |
secret.update(token.encode('utf-8')) | |
sorted_params = collections.OrderedDict(sorted(data.items())) | |
param_hash = data.get('hash', '') | |
msg = "\n".join(["{}={}".format(k, v) for k, v in sorted_params.items() if k != 'hash']) | |
return param_hash == hmac.new(secret.digest(), msg.encode('utf-8'), digestmod=hashlib.sha256).hexdigest(): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment