From 31dda63f4335541178d6663eaa26a49dc6cea822 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Tue, 24 Dec 2024 06:30:33 -0500 Subject: [PATCH] Don't enforce user IDs in oss mode (#5776) --- openhands/server/listen_socket.py | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/openhands/server/listen_socket.py b/openhands/server/listen_socket.py index d0c917fad58f..c9fba18ed511 100644 --- a/openhands/server/listen_socket.py +++ b/openhands/server/listen_socket.py @@ -14,7 +14,8 @@ from openhands.events.serialization import event_to_dict from openhands.events.stream import AsyncEventStreamWrapper from openhands.server.session.manager import ConversationDoesNotExistError -from openhands.server.shared import config, session_manager, sio +from openhands.server.shared import config, openhands_config, session_manager, sio +from openhands.server.types import AppMode from openhands.storage.conversation.conversation_store import ( ConversationStore, ) @@ -31,23 +32,24 @@ async def connect(connection_id: str, environ, auth): logger.error('No conversation_id in query params') raise ConnectionRefusedError('No conversation_id in query params') - user_id = '' - if auth and 'github_token' in auth: - with Github(auth['github_token']) as g: - gh_user = await call_sync_from_async(g.get_user) - user_id = gh_user.id + if openhands_config.app_mode != AppMode.OSS: + user_id = '' + if auth and 'github_token' in auth: + with Github(auth['github_token']) as g: + gh_user = await call_sync_from_async(g.get_user) + user_id = gh_user.id - logger.info(f'User {user_id} is connecting to conversation {conversation_id}') + logger.info(f'User {user_id} is connecting to conversation {conversation_id}') - conversation_store = await ConversationStore.get_instance(config) - metadata = await conversation_store.get_metadata(conversation_id) - if metadata.github_user_id != user_id: - logger.error( - f'User {user_id} is not allowed to join conversation {conversation_id}' - ) - raise ConnectionRefusedError( - f'User {user_id} is not allowed to join conversation {conversation_id}' - ) + conversation_store = await ConversationStore.get_instance(config) + metadata = await conversation_store.get_metadata(conversation_id) + if metadata.github_user_id != user_id: + logger.error( + f'User {user_id} is not allowed to join conversation {conversation_id}' + ) + raise ConnectionRefusedError( + f'User {user_id} is not allowed to join conversation {conversation_id}' + ) try: event_stream = await session_manager.join_conversation(