TelegramAktienBot/api/app/auth.py
H4CK3R-01 21d2bc334c Tests
- Improved directory structure
- Added functional and unit tests
2022-03-30 10:46:54 +02:00

22 lines
421 B
Python

from flask import current_app
import jwt
from apiflask import HTTPTokenAuth
auth = HTTPTokenAuth()
@auth.verify_token
def verify_token(token):
if token is None:
return False
if ':' in token: # Bot token
token = token.split(":")[0]
try:
jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=["HS256"])
return True
except jwt.PyJWTError:
return False