mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 07:18:10 -05:00
Move GH Token retrieval to GitHubService class (#6605)
Co-authored-by: tofarr <tofarr@gmail.com>
This commit is contained in:
@@ -39,10 +39,10 @@ async def connect(connection_id: str, environ, auth):
|
||||
if server_config.app_mode != AppMode.OSS:
|
||||
cookies_str = environ.get('HTTP_COOKIE', '')
|
||||
cookies = dict(cookie.split('=', 1) for cookie in cookies_str.split('; '))
|
||||
signed_token = cookies.get('github_auth', '')
|
||||
signed_token = cookies.get('openhands_auth', '')
|
||||
if not signed_token:
|
||||
logger.error('No github_auth cookie')
|
||||
raise ConnectionRefusedError('No github_auth cookie')
|
||||
logger.error('No openhands_auth cookie')
|
||||
raise ConnectionRefusedError('No openhands_auth cookie')
|
||||
if not config.jwt_secret:
|
||||
raise RuntimeError('JWT secret not found')
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ from openhands.utils.import_utils import get_impl
|
||||
|
||||
app = APIRouter(prefix='/api/github')
|
||||
|
||||
|
||||
GithubServiceImpl = get_impl(GitHubService, server_config.github_service_class)
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.events.action.message import MessageAction
|
||||
from openhands.events.stream import EventStreamSubscriber
|
||||
from openhands.runtime import get_runtime_cls
|
||||
from openhands.server.auth import get_github_token, get_user_id
|
||||
from openhands.server.auth import get_user_id
|
||||
from openhands.server.routes.github import GithubServiceImpl
|
||||
from openhands.server.session.conversation_init_data import ConversationInitData
|
||||
from openhands.server.shared import (
|
||||
ConversationStoreImpl,
|
||||
@@ -130,7 +131,7 @@ async def new_conversation(request: Request, data: InitSessionRequest):
|
||||
"""
|
||||
logger.info('Initializing new conversation')
|
||||
user_id = get_user_id(request)
|
||||
github_token = get_github_token(request)
|
||||
github_token = GithubServiceImpl.get_gh_token(request)
|
||||
selected_repository = data.selected_repository
|
||||
initial_user_msg = data.initial_user_msg
|
||||
image_urls = data.image_urls or []
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
from fastapi import Request
|
||||
|
||||
from openhands.server.auth import get_github_token
|
||||
from openhands.server.data_models.gh_types import GitHubRepository, GitHubUser
|
||||
from openhands.server.shared import SettingsStoreImpl, config, server_config
|
||||
from openhands.server.types import AppMode, GhAuthenticationError, GHUnknownException
|
||||
@@ -131,3 +133,7 @@ class GitHubService:
|
||||
]
|
||||
|
||||
return repos
|
||||
|
||||
@classmethod
|
||||
def get_gh_token(cls, request: Request) -> str | None:
|
||||
return get_github_token(request)
|
||||
|
||||
Reference in New Issue
Block a user