This commit is contained in:
Timothy Jaeryang Baek 2026-08-24 18:38:29 -04:00
parent 9dff5e9327
commit 97466deea1
5 changed files with 26 additions and 30 deletions

View file

@ -49,7 +49,7 @@ from open_webui.retrieval.vector.main import GetResult, SearchResult
from open_webui.retrieval.web.utils import get_web_loader
from open_webui.utils.access_control.files import get_owner_accessible_folder_files, has_access_to_file
from open_webui.utils.access_control.folders import has_folder_access
from open_webui.utils.headers import include_user_info_headers
from open_webui.utils.headers import get_json_bearer_headers, include_user_info_headers
from open_webui.utils.misc import get_content_from_message, get_message_list
log = logging.getLogger(__name__)
@ -879,10 +879,7 @@ def generate_openai_batch_embeddings(
if isinstance(RAG_EMBEDDING_PREFIX_FIELD_NAME, str) and isinstance(prefix, str):
json_data[RAG_EMBEDDING_PREFIX_FIELD_NAME] = prefix
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {key}',
}
headers = get_json_bearer_headers(key)
if ENABLE_FORWARD_USER_INFO_HEADERS and user:
headers = include_user_info_headers(headers, user)
@ -912,10 +909,7 @@ async def agenerate_openai_batch_embeddings(
if isinstance(RAG_EMBEDDING_PREFIX_FIELD_NAME, str) and isinstance(prefix, str):
form_data[RAG_EMBEDDING_PREFIX_FIELD_NAME] = prefix
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {key}',
}
headers = get_json_bearer_headers(key)
if ENABLE_FORWARD_USER_INFO_HEADERS and user:
headers = include_user_info_headers(headers, user)
@ -1031,10 +1025,7 @@ def generate_ollama_batch_embeddings(
if isinstance(RAG_EMBEDDING_PREFIX_FIELD_NAME, str) and isinstance(prefix, str):
json_data[RAG_EMBEDDING_PREFIX_FIELD_NAME] = prefix
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {key}',
}
headers = get_json_bearer_headers(key)
if ENABLE_FORWARD_USER_INFO_HEADERS and user:
headers = include_user_info_headers(headers, user)
@ -1067,10 +1058,7 @@ async def agenerate_ollama_batch_embeddings(
if isinstance(RAG_EMBEDDING_PREFIX_FIELD_NAME, str) and isinstance(prefix, str):
form_data[RAG_EMBEDDING_PREFIX_FIELD_NAME] = prefix
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {key}',
}
headers = get_json_bearer_headers(key)
if ENABLE_FORWARD_USER_INFO_HEADERS and user:
headers = include_user_info_headers(headers, user)

View file

@ -13,7 +13,7 @@ from open_webui.events import EVENTS, publish_event
from open_webui.models.config import Config
from open_webui.models.oauth_sessions import OAuthSessions
from open_webui.utils.auth import get_admin_user, get_verified_user
from open_webui.utils.headers import get_custom_headers
from open_webui.utils.headers import bearer_auth_header, get_custom_headers
from open_webui.utils.mcp.client import MCPClient
from open_webui.utils.oauth import (
OAuthClientInformationFull,
@ -27,7 +27,6 @@ from open_webui.utils.oauth import (
resolve_oauth_client_info,
)
from open_webui.utils.tools import (
bearer_auth_header,
get_tool_server_data,
get_tool_server_url,
set_terminal_servers,

View file

@ -19,6 +19,7 @@ from open_webui.models.config import Config
from open_webui.models.groups import Groups
from open_webui.utils.access_control import has_connection_access
from open_webui.utils.auth import get_verified_user
from open_webui.utils.headers import bearer_auth_header, normalize_bearer_token
from open_webui.utils.json_codec import JSONCodec
from open_webui.utils.terminals import (
TERMINAL_CONTEXT_HEADER,
@ -30,7 +31,6 @@ from open_webui.utils.terminals import (
terminal_chat_uploads,
terminal_contexts,
)
from open_webui.utils.tools import bearer_auth_header, normalize_bearer_token
from starlette.background import BackgroundTask
from starlette.requests import ClientDisconnect

View file

@ -20,6 +20,19 @@ log = logging.getLogger(__name__)
USER_GROUPS_PLACEHOLDERS = ('{{USER_GROUPS}}', '{{USER_GROUP_IDS}}')
def normalize_bearer_token(token: Any) -> str:
return token.strip() if isinstance(token, str) else token or ''
def bearer_auth_header(token: Any) -> dict[str, str]:
token = normalize_bearer_token(token)
return {'Authorization': f'Bearer {token}'} if token else {}
def get_json_bearer_headers(token: Any = '') -> dict[str, str]:
return {'Content-Type': 'application/json', **bearer_auth_header(token)}
def _mint_forward_user_jwt(user: Any) -> str:
now = int(time.time())
payload = {

View file

@ -102,7 +102,12 @@ from open_webui.tools.builtin import (
)
from open_webui.utils.access_control import has_access, has_connection_access, has_permission
from open_webui.utils.chat_id import is_saved_chat_id
from open_webui.utils.headers import get_custom_headers, include_user_info_headers
from open_webui.utils.headers import (
bearer_auth_header,
get_custom_headers,
include_user_info_headers,
normalize_bearer_token,
)
from open_webui.utils.json_codec import JSONCodec
from open_webui.utils.misc import is_string_allowed
from open_webui.utils.plugin import get_tool_contents_cache, get_tools_cache, load_tool_module_by_id
@ -119,15 +124,6 @@ from pydantic.fields import FieldInfo
log = logging.getLogger(__name__)
def normalize_bearer_token(token: Any) -> str:
return token.strip() if isinstance(token, str) else token or ''
def bearer_auth_header(token: Any) -> dict[str, str]:
token = normalize_bearer_token(token)
return {'Authorization': f'Bearer {token}'} if token else {}
async def build_tool_server_headers(
connection: dict,
request,