Tests
- Improved directory structure - Added functional and unit tests
This commit is contained in:
21
api/app/auth.py
Normal file
21
api/app/auth.py
Normal file
@@ -0,0 +1,21 @@
|
||||
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
|
Reference in New Issue
Block a user