Last active
June 24, 2022 23:38
-
-
Save jainamoswal/279e5259a5c24f37cd44ea446c373ac4 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
from flask import Flask, request, redirect | |
from utils import verify | |
app = Flask(__name__) | |
@app.route('/') | |
def main(): | |
if verify(request.args.to_dict()) == request.args.get('hash'): | |
return f"Hey {request.args.get('first_name')}!" | |
else: | |
return "Sorry, You didn't clicked the Auth Button and just redirected here." | |
if __name__ == '__main__': | |
app.run() |
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 hashlib | |
import hmac | |
BOT_TOKEN = '1797603327:AAFFCpZIU1pvq4-hL5pmgX4IJR7LtLL9xfU' | |
def verify(request_data): | |
request_data = request_data.copy() | |
request_data.pop('hash', None) | |
request_data_alphabetical_order = sorted(request_data.items(), key=lambda x: x[0]) | |
data_check_string = [] | |
for data_pair in request_data_alphabetical_order: | |
key, value = data_pair[0], data_pair[1] | |
data_check_string.append(f"{key}={value}") | |
data_check_string = '\n'.join(data_check_string) | |
secret_key = hashlib.sha256(BOT_TOKEN.encode()).digest() | |
return hmac.new(secret_key, msg=data_check_string.encode(), digestmod=hashlib.sha256).hexdigest() |
Author
jainamoswal
commented
Apr 18, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment