From 4ca0ea1e55b81f7ba29f4adf288ebb89c8cc4da6 Mon Sep 17 00:00:00 2001 From: hurxxxx Date: Wed, 7 May 2025 00:03:07 +0900 Subject: [PATCH] Add SharePoint tenant ID to OneDrive settings --- backend/open_webui/config.py | 5 +++++ backend/open_webui/main.py | 3 +++ src/lib/utils/onedrive-file-picker.ts | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index a6cffeecd..b188bc462 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -1824,6 +1824,11 @@ ONEDRIVE_SHAREPOINT_URL = PersistentConfig( os.environ.get("ONEDRIVE_SHAREPOINT_URL", ""), ) +ONEDRIVE_SHAREPOINT_TENANT_ID = PersistentConfig( + "ONEDRIVE_SHAREPOINT_TENANT_ID", + "onedrive.sharepoint_tenant_id", + os.environ.get("ONEDRIVE_SHAREPOINT_TENANT_ID", ""), +) # RAG Content Extraction CONTENT_EXTRACTION_ENGINE = PersistentConfig( diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index db124bedd..d936d6f10 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -103,6 +103,7 @@ from open_webui.config import ( ENABLE_OPENAI_API, ONEDRIVE_CLIENT_ID, ONEDRIVE_SHAREPOINT_URL, + ONEDRIVE_SHAREPOINT_TENANT_ID, OPENAI_API_BASE_URLS, OPENAI_API_KEYS, OPENAI_API_CONFIGS, @@ -254,6 +255,7 @@ from open_webui.config import ( GOOGLE_DRIVE_API_KEY, ONEDRIVE_CLIENT_ID, ONEDRIVE_SHAREPOINT_URL, + ONEDRIVE_SHAREPOINT_TENANT_ID, ENABLE_RAG_HYBRID_SEARCH, ENABLE_RAG_LOCAL_WEB_FETCH, ENABLE_WEB_LOADER_SSL_VERIFICATION, @@ -1379,6 +1381,7 @@ async def get_app_config(request: Request): "onedrive": { "client_id": ONEDRIVE_CLIENT_ID.value, "sharepoint_url": ONEDRIVE_SHAREPOINT_URL.value, + "sharepoint_tenant_id": ONEDRIVE_SHAREPOINT_TENANT_ID.value, }, "license_metadata": app.state.LICENSE_METADATA, **( diff --git a/src/lib/utils/onedrive-file-picker.ts b/src/lib/utils/onedrive-file-picker.ts index 180840524..59ac52473 100644 --- a/src/lib/utils/onedrive-file-picker.ts +++ b/src/lib/utils/onedrive-file-picker.ts @@ -6,6 +6,7 @@ class OneDriveConfig { private static instance: OneDriveConfig; private clientId: string = ''; private sharepointUrl: string = ''; + private sharepointTenantId: string = ''; private msalInstance: PublicClientApplication | null = null; private currentAuthorityType: 'personal' | 'organizations' = 'personal'; @@ -39,7 +40,7 @@ class OneDriveConfig { headers, credentials: 'include' }); - + if (!response.ok) { throw new Error('Failed to fetch OneDrive credentials'); } @@ -48,6 +49,7 @@ class OneDriveConfig { const newClientId = config.onedrive?.client_id; const newSharepointUrl = config.onedrive?.sharepoint_url; + const newSharepointTenantId = config.onedrive?.sharepoint_tenant_id; if (!newClientId) { throw new Error('OneDrive configuration is incomplete'); @@ -55,6 +57,7 @@ class OneDriveConfig { this.clientId = newClientId; this.sharepointUrl = newSharepointUrl; + this.sharepointTenantId = newSharepointTenantId; } public async getMsalInstance( @@ -63,8 +66,9 @@ class OneDriveConfig { await this.ensureInitialized(authorityType); if (!this.msalInstance) { - const authorityEndpoint = - this.currentAuthorityType === 'organizations' ? 'common' : 'consumers'; + const authorityEndpoint = this.currentAuthorityType === 'organizations' + ? (this.sharepointTenantId || 'common') + : 'consumers'; const msalParams = { auth: { authority: `https://login.microsoftonline.com/${authorityEndpoint}`, @@ -89,6 +93,10 @@ class OneDriveConfig { return this.sharepointUrl; } + public getSharepointTenantId(): string { + return this.sharepointTenantId; + } + public getBaseUrl(): string { if (this.currentAuthorityType === 'organizations') { if (!this.sharepointUrl || this.sharepointUrl === '') {