Browse Source
refactor: simplify auth_header generation in API key authentication
pull/13326/head
Manish
1 month ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
1 additions and
7 deletions
-
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", |
|
|
|