-
Notifications
You must be signed in to change notification settings - Fork 5
/
authenticate.py
32 lines (23 loc) · 1.11 KB
/
authenticate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pymessenger.bot import Bot
import os
ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN")
VERIFY_TOKEN = os.environ.get("VERIFICATION_TOKEN")
ADMIN = os.environ.get("ADMIN")
#SQL Database
import mysql.connector
connection = mysql.connector.connect(user= os.environ.get("DB_USER"),
password= os.environ.get("DB_PASS"),
host= os.environ.get("DB_HOST"),
db= os.environ.get("DB"))
def verify_bot_access():
return Bot(ACCESS_TOKEN)
#Matches VERIFY_TOKEN with Verification token provided to Fb for web Hook #This ensures that the bot only responds to requests from messenger
def verify_fb_token(request):
token_sent = request.args.get("hub.verify_token")
if (token_sent == VERIFY_TOKEN):
#verification token matches, return expected message
return request.args.get("hub.challenge")
#Verification token doesn't match
return ("<h1>Access Denied: No Proper Rights!!<h1>")
def is_admin(user_id):
return user_id == ADMIN