Skip to content

Commit

Permalink
Add alternative auth header (#2999)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weves authored Oct 30, 2024
1 parent 8223dc7 commit 5be457e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/ee/danswer/auth/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@


_API_KEY_HEADER_NAME = "Authorization"
# NOTE for others who are curious: In the context of a header, "X-" often refers
# to non-standard, experimental, or custom headers in HTTP or other protocols. It
# indicates that the header is not part of the official standards defined by
# organizations like the Internet Engineering Task Force (IETF).
_API_KEY_HEADER_ALTERNATIVE_NAME = "X-Danswer-Authorization"
_BEARER_PREFIX = "Bearer "
_API_KEY_PREFIX = "dn_"
_API_KEY_LEN = 192
Expand Down Expand Up @@ -43,7 +48,9 @@ def build_displayable_api_key(api_key: str) -> str:


def get_hashed_api_key_from_request(request: Request) -> str | None:
raw_api_key_header = request.headers.get(_API_KEY_HEADER_NAME)
raw_api_key_header = request.headers.get(
_API_KEY_HEADER_ALTERNATIVE_NAME
) or request.headers.get(_API_KEY_HEADER_NAME)
if raw_api_key_header is None:
return None

Expand Down

0 comments on commit 5be457e

Please sign in to comment.