proxmox-api-container/app/utils/authorization.py

22 lines
533 B
Python
Raw Normal View History

2024-01-15 12:32:53 +00:00
from functools import wraps
from flask import request
import os
def token_required(f):
@wraps(f)
def decorated(*args, **kwargs):
print('request.headers: ', request.headers)
token = None
if 'x-api-key' in request.headers:
token = request.headers['x-api-key']
if not token:
return {'message': "Token not found"}, 401
if token != os.getenv('TOKEN'):
return {'message': "Invalid token"}, 401
return f(*args, **kwargs)
return decorated