Skip to content

Commit

Permalink
Don't enforce user IDs in oss mode (#5776)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren authored Dec 24, 2024
1 parent ecff5c6 commit 31dda63
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions openhands/server/listen_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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(
Expand Down

0 comments on commit 31dda63

Please sign in to comment.