Add SharePoint tenant ID to OneDrive settings

This commit is contained in:
hurxxxx 2025-05-07 00:03:07 +09:00
parent 23b9354cf6
commit 4ca0ea1e55
3 changed files with 19 additions and 3 deletions

View File

@ -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(

View File

@ -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,
**(

View File

@ -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 === '') {