2022-04-12 07:50:24 +00:00
|
|
|
__author__ = "Florian Kaiser"
|
|
|
|
__copyright__ = "Copyright 2022, Project Aktienbot"
|
|
|
|
__credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"]
|
|
|
|
__license__ = "GPL 3.0"
|
|
|
|
__version__ = "1.0.0"
|
|
|
|
|
2022-03-30 08:46:54 +00:00
|
|
|
from flask import current_app
|
2022-03-17 08:26:25 +00:00
|
|
|
|
|
|
|
import jwt
|
|
|
|
from apiflask import HTTPTokenAuth
|
|
|
|
|
|
|
|
auth = HTTPTokenAuth()
|
|
|
|
|
|
|
|
|
|
|
|
@auth.verify_token
|
|
|
|
def verify_token(token):
|
|
|
|
if token is None:
|
|
|
|
return False
|
|
|
|
|
2022-04-12 09:36:23 +00:00
|
|
|
# We decided to append the user id to the bearer token using ":" as separator to select an specific user
|
|
|
|
# To validate the token we can remove the user id since we only validate the token and not the user id
|
|
|
|
if ':' in token:
|
2022-03-22 10:20:04 +00:00
|
|
|
token = token.split(":")[0]
|
|
|
|
|
2022-03-17 08:26:25 +00:00
|
|
|
try:
|
2022-03-30 08:46:54 +00:00
|
|
|
jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=["HS256"])
|
2022-03-17 08:26:25 +00:00
|
|
|
return True
|
2022-03-27 18:03:11 +00:00
|
|
|
except jwt.PyJWTError:
|
2022-03-17 08:26:25 +00:00
|
|
|
return False
|