Commit 8e6f7268 authored by kurumuz's avatar kurumuz

verify token clean

parent 4e346860
......@@ -37,33 +37,6 @@ mainpid = config.mainpid
hostname = socket.gethostname()
sent_first_message = False
def auth_required(handler):
async def wrapper(raw_request: Request, *args, **kwargs):
if TOKEN:
print("got here")
authorization = raw_request.headers.get("authorization")
if authorization is None or authorization != "Bearer "+TOKEN:
return ErrorOutput(error="invalid token")
return await handler(*args, **kwargs)
# Fix signature of wrapper
import inspect
wrapper.__signature__ = inspect.Signature(
parameters = [
# Use all parameters from handler
*inspect.signature(handler).parameters.values(),
# Skip *args and **kwargs from wrapper parameters:
*filter(
lambda p: p.kind not in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD),
inspect.signature(wrapper).parameters.values()
)
],
return_annotation = inspect.signature(handler).return_annotation,
)
return wrapper
def verify_token(req: Request):
valid = "Authorization" in req.headers and req.headers["Authorization"] == "Bearer "+TOKEN
if not valid:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment