From bfa95a6180cec10ef669b7a438e75bd59e2cf2e4 Mon Sep 17 00:00:00 2001 From: Manish <88748362+mnshai@users.noreply.github.com> Date: Mon, 3 Mar 2025 14:30:25 +0530 Subject: [PATCH] refactor: simplify auth_header generation in API key authentication --- fastapi/security/api_key.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/fastapi/security/api_key.py b/fastapi/security/api_key.py index a0c34caed..943877c8f 100644 --- a/fastapi/security/api_key.py +++ b/fastapi/security/api_key.py @@ -15,13 +15,7 @@ class APIKeyBase(SecurityBase): ) -> Optional[str]: if not api_key: if auto_error: - # Customize header based on where the API key should be - auth_header = { - APIKeyIn.query: f'ApiKey name="{key_name}", in="query"', - APIKeyIn.header: f'ApiKey name="{key_name}", in="header"', - APIKeyIn.cookie: f'ApiKey name="{key_name}", in="cookie"', - }.get(key_in, "ApiKey") - + auth_header = f'ApiKey name="{key_name}", in="{key_in.value}"' raise HTTPException( status_code=HTTP_401_UNAUTHORIZED, detail="Not authenticated",