Skip to content

Commit

Permalink
fix: try auth user to handle api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
okradze committed Dec 12, 2023
1 parent cd324f3 commit 9afa5bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/server/controllers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
NegotiateOutput, UpdateChatInput)
from typings.config import ConfigOutput
from utils.auth import (authenticate, authenticate_by_token_or_api_key,
try_auth_user)
try_auth_user, try_auth_user_with_token_or_api_key)
from utils.chat import (convert_chats_to_chat_list, convert_model_to_response,
get_chat_session_id)
from utils.configuration import \
Expand Down Expand Up @@ -277,7 +277,7 @@ def create_chat_message(request: Request, response: Response, body: ChatMessageI
Create new chat message
"""
# authenticate
auth: UserAccount = try_auth_user(request, response)
auth: UserAccount = try_auth_user_with_token_or_api_key(request, response)
return create_client_message(body, auth)


Expand Down
10 changes: 10 additions & 0 deletions apps/server/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def authenticate_by_auth_token(
raise HTTPException(status_code=401, detail="Invalid auth token")


def try_auth_user_with_token_or_api_key(
request: Request, response: Response
) -> Tuple[UserOutput, AccountOutput]:
try:
return authenticate_by_token_or_api_key(request, response)
except Exception:
return None


# TODO: reuse from authenticate_by_token_or_api_key and then remove try_auth_user_with_token_or_api_key
def try_auth_user(
request: Request, response: Response
) -> Tuple[UserOutput, AccountOutput]:
Expand Down

0 comments on commit 9afa5bf

Please sign in to comment.