From 1832db4cdcb26dd8443d160e93586c9ba831ecb0 Mon Sep 17 00:00:00 2001 From: Valbou Date: Sat, 25 May 2024 09:57:48 +0200 Subject: [PATCH] feat: add auth methods --- src/libs/flask/utils/request_helpers.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libs/flask/utils/request_helpers.py b/src/libs/flask/utils/request_helpers.py index dcbcaeb2..bf1081e0 100644 --- a/src/libs/flask/utils/request_helpers.py +++ b/src/libs/flask/utils/request_helpers.py @@ -1,5 +1,9 @@ +import logging + from flask import Request +logger = logging.getLogger(__name__) + BEARER = "Bearer " @@ -11,18 +15,24 @@ def get_bearer_token(request: Request) -> str | None: def get_payload_token(request: Request) -> str | None: - token = request.get_json().get("token") - return token + return request.get_json().get("token") + + +def get_querystring_token(request: Request) -> str | None: + return request.args.to_dict().get("token") def get_auth_token(request: Request) -> str | None: token = None - methods = [get_bearer_token, get_payload_token] + methods = [get_bearer_token, get_payload_token, get_querystring_token] for method in methods: - token = method(request=request) - if token: - break + try: + token = method(request=request) + if token: + break + except Exception as e: + logger.debug(f"Error in method {method.__name__}: {e}") return token