# 📋 Solicitud de Soporte Técnico - Microsoft Azure AI Foundry **Fecha**: 4 de noviembre de 2025 **Empresa**: e-intelligent **Contacto**: jorge.garcia.riego@e-intelligent.es **Tenant ID**: `2c4d6781-5a64-4cf2-b233-ced387dbebab` --- ## 🎯 Resumen del Problema Tenemos dos endpoints implementados usando **Azure AI Projects SDK** (.NET): - ✅ **`/api/drupal-ai/ask2`** - Funciona perfectamente con Vector Store - ❌ **`/api/drupal-ai/ask-sharepoint`** - Falla con error "AppOnly OBO tokens not supported" Ambos endpoints usan la misma arquitectura y Azure AI Projects SDK, pero el endpoint de SharePoint falla en la autenticación cuando intenta acceder al SharePoint tool configurado en Azure AI Foundry. --- ## 🏗️ Arquitectura de la Solución ### Tecnologías Utilizadas - **Framework**: ASP.NET Core 9.0 - **SDK**: Azure.AI.Projects v1.0.0-beta.9 - **SDK**: Azure.AI.Agents.Persistent v1.1.0-beta.2 - **SDK**: Azure.Identity v1.14.1 - **Autenticación**: ClientSecretCredential (Service Principal) - **Plataforma**: Azure AI Foundry ### Componentes de Azure ``` Azure AI Foundry Project ├── Azure OpenAI Service (gpt-4o-mini) ├── Azure AI Search (Vector Store) ├── Agent 1 (asst_VwCt6zBWUkIhcqaFgiG9vUio) ✅ Funciona │ └── Tool: file_search │ └── Vector Store: vs_OGPMUu5KbDHNgVE04xj2vkDq │ └── Agent 2 (asst_6Ov3yAdqlTGOMEa4UzqRGobn) ❌ Falla └── Tool: SharePoint (RAG_Sharepoint_Assitant) └── Error: "AppOnly OBO tokens not supported" ``` ### Endpoint de Azure AI Projects ``` https://vicubo-service-ia.services.ai.azure.com/api/projects/vicubo-ia-chat-assistant ``` --- ## ✅ Endpoint que FUNCIONA: `/api/drupal-ai/ask2` ### Configuración del Agente ```json { "AgentId": "asst_VwCt6zBWUkIhcqaFgiG9vUio", "Model": "gpt-4o-mini", "Tools": [{ "type": "file_search" }], "VectorStoreIds": ["vs_OGPMUu5KbDHNgVE04xj2vkDq"] } ``` ### Autenticación ```csharp var credential = new ClientSecretCredential( tenantId: "2c4d6781-5a64-4cf2-b233-ced387dbebab", clientId: "cb2952e0-d4a2-4101-a868-734874f6790f", clientSecret: "XXXXXX" ); ``` ### Service Principal Configurado - **Display Name**: VicuboAI-SharePoint-Agent - **Application ID**: `cb2952e0-d4a2-4101-a868-734874f6790f` - **Object ID**: `0ceabe58-6805-4351-a085-b5d950c7cf63` - **Roles Asignados**: - ✅ Azure AI Developer (Azure AI Foundry) - ✅ Cognitive Services OpenAI User ### Código de Implementación ```csharp public async Task RunAgentConversationAsync(string question) { // 1. Crear credencial var credential = new ClientSecretCredential(tenantId, clientId, clientSecret); // 2. Crear cliente del proyecto AIProjectClient projectClient = new AIProjectClient(endpoint, credential); PersistentAgentsClient agentsClient = projectClient.GetPersistentAgentsClient(); // 3. Obtener agente PersistentAgent agent = agentsClient.Administration.GetAgent(_agentId); // 4. Crear thread PersistentAgentThread thread = agentsClient.Threads.CreateThread(); // 5. Agregar mensaje PersistentThreadMessage messageResponse = agentsClient.Messages.CreateMessage( thread.Id, MessageRole.User, question ); // 6. Ejecutar run ThreadRun run = agentsClient.Runs.CreateRun(thread.Id, agent.Id); // 7. Polling hasta completar do { await Task.Delay(500); run = agentsClient.Runs.GetRun(thread.Id, run.Id); } while (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress); // 8. Obtener mensajes Pageable messages = agentsClient.Messages.GetMessages(thread.Id); return new { messages }; } ``` ### Request de Prueba (PowerShell) ```powershell curl -X POST http://localhost:5122/api/drupal-ai/ask2 ` -H "Content-Type: application/json" ` -H "x-api-key: XXXX" ` -d '{"question":"¿Cómo configurar RSS en el sistema?"}' ``` ### Response Exitoso ```json { "threadId": "thread_abc123", "agentId": "asst_VwCt6zBWUkIhcqaFgiG9vUio", "authenticationMethod": "ClientSecretCredential", "messages": [ { "timestamp": "2025-11-04 10:30:00", "role": "user", "content": "¿Cómo configurar RSS en el sistema?" }, { "timestamp": "2025-11-04 10:30:05", "role": "assistant", "content": "Para configurar RSS... [respuesta basada en vector store]" } ] } ``` --- ## ❌ Endpoint que FALLA: `/api/drupal-ai/ask-sharepoint` ### Configuración del Agente ```json { "AgentId": "asst_6Ov3yAdqlTGOMEa4UzqRGobn", "TenantId": "2c4d6781-5a64-4cf2-b233-ced387dbebab", "ApplicationId": "cb2952e0-d4a2-4101-a868-734874f6790f", "ClientSecretValue": "XXXXXXXXXXX", "SharePointConnectionName": "RAG_Sharepoint_Assitant" } ``` ### Autenticación (Idéntica al endpoint que funciona) ```csharp var credential = new ClientSecretCredential( tenantId: "2c4d6781-5a64-4cf2-b233-ced387dbebab", clientId: "cb2952e0-d4a2-4101-a868-734874f6790f", clientSecret: "XXXXXXXXXXXX" ); ``` ### Código de Implementación ```csharp public async Task RunSharePointAgentConversationAsync(string question) { // MISMO CÓDIGO que RunAgentConversationAsync, solo cambia: // 1. El AgentId usado: asst_6Ov3yAdqlTGOMEa4UzqRGobn // 2. El agente en Azure AI Foundry tiene configurado SharePoint tool var sharePointAgentId = "asst_6Ov3yAdqlTGOMEa4UzqRGobn"; // Misma autenticación var credential = new ClientSecretCredential(spTenantId, spClientId, spClientSecret); // Mismo flujo AIProjectClient projectClient = new AIProjectClient(endpoint, credential); PersistentAgentsClient agentsClient = projectClient.GetPersistentAgentsClient(); PersistentAgent agent = agentsClient.Administration.GetAgent(sharePointAgentId); // ... resto del código idéntico ... } ``` ### Request de Prueba (PowerShell) ```powershell curl -X POST http://localhost:5122/api/drupal-ai/ask-sharepoint ` -H "Content-Type: application/json" ` -H "x-api-key: CAMBIA_ESTA_API_KEY" ` -d '{"question":"¿Qué documentos hay en SharePoint?"}' ``` ### Error Recibido ```json { "error": "Run failed or was canceled: sharepoint_tool_user_error; AppOnly OBO tokens not supported by target service", "status": "Failed" } ``` ### Logs del Servidor ``` ✅ Starting SharePoint conversation with agent ID: asst_6Ov3yAdqlTGOMEa4UzqRGobn ✅ Using AzureAIAgentSharePoint credentials: ✅ - Tenant ID: 2c4d6781-5a64-4cf2-b233-ced387dbebab ✅ - Application ID: cb2952e0-d4a2-4101-a868-734874f6790f ✅ - Client Secret length: 40 ✅ Authentication method: ClientSecretCredential (SharePoint App) ✅ SharePoint agent retrieved: asst_6Ov3yAdqlTGOMEa4UzqRGobn ✅ Thread created: thread_xyz789 ✅ Message added: ¿Qué documentos hay en SharePoint? ✅ Run created: run_abc456 ⏳ Polling run status... ⏳ Run status: InProgress (attempt 1) ⏳ Run status: InProgress (attempt 2) ❌ Run status: Failed (attempt 3) ❌ Run failed or was canceled: sharepoint_tool_user_error; AppOnly OBO tokens not supported by target service ``` --- ## 🔍 Análisis del Error ### Error Completo ``` sharepoint_tool_user_error; AppOnly OBO tokens not supported by target service ``` ### Interpretación - **AppOnly**: Autenticación usando Application/Service Principal (sin usuario) - **OBO tokens**: On-Behalf-Of tokens (requiere usuario real) - **not supported**: El SharePoint tool de Azure AI Foundry NO acepta App-Only auth ### Diferencias entre Endpoints | Aspecto | `/ask2` (✅ Funciona) | `/ask-sharepoint` (❌ Falla) | |---------|---------------------|---------------------------| | **SDK** | Azure.AI.Projects | Azure.AI.Projects | | **Autenticación** | ClientSecretCredential | ClientSecretCredential | | **Service Principal** | Mismo | Mismo | | **Agent Tool** | file_search | SharePoint | | **Error** | Ninguno | AppOnly OBO not supported | ### Hipótesis El **SharePoint tool en Azure AI Foundry** requiere autenticación delegada (OBO) y no acepta autenticación de aplicación (App-Only), a diferencia de otros tools como file_search. --- ## ❓ Preguntas para Microsoft Support ### 1. Limitación del SharePoint Tool **¿Es correcto que el SharePoint tool en Azure AI Foundry NO soporta autenticación App-Only (Service Principal)?** Si es así: - ¿Está documentado en algún lugar? - ¿Cuál es la razón técnica? - ¿Hay planes de soportarlo en el futuro? ### 2. Alternativas con Service Principal **¿Existe alguna forma de usar el SharePoint tool con Service Principal?** Hemos intentado: - ✅ Asignar permisos "Azure AI Developer" - ✅ Usar ClientSecretCredential correctamente - ✅ Configurar Application Permissions en Azure AD - ❌ Aún así falla con "AppOnly OBO tokens not supported" ### 3. Configuración de Autenticación Delegada **Si debemos usar autenticación delegada (OBO), ¿cómo configurarlo en un servicio backend sin interacción de usuario?** Nuestro caso de uso: - Servicio Web API en ASP.NET Core - Sin frontend/UI - Llamadas automatizadas desde Drupal - No hay usuario interactivo disponible **¿Es posible usar OBO sin interacción de usuario?** ### 4. Permisos de SharePoint **¿Qué permisos específicos necesita el Service Principal en SharePoint?** Actualmente tenemos: - `Sites.Read.All` (Application Permission) - `Files.Read.All` (Application Permission) ¿Son suficientes o necesitamos otros? ### 5. Configuración del Agent en Azure AI Foundry **¿Hay alguna configuración específica en el Agent de Azure AI Foundry para habilitar App-Only auth con SharePoint?** En el portal de Azure AI Foundry: - Agent → Tools → SharePoint - ¿Hay opciones de autenticación? - ¿Cómo se configura la conexión a SharePoint? ### 6. Alternativas Recomendadas **¿Cuál es la arquitectura recomendada por Microsoft para este escenario?** Opciones consideradas: 1. ❌ App-Only con SharePoint tool (actual - no funciona) 2. ❓ OBO con Interactive Login (no aplicable para API backend) 3. ❓ Usar Microsoft Graph API directamente + RAG custom 4. ❓ Otro enfoque recomendado por Microsoft --- ## 📊 Configuración Actual de Azure ### Service Principal ```yaml Display Name: VicuboAI-SharePoint-Agent Application (Client) ID: cb2952e0-d4a2-4101-a868-734874f6790f Object ID: 0ceabe58-6805-4351-a085-b5d950c7cf63 Tenant ID: 2c4d6781-5a64-4cf2-b233-ced387dbebab ``` ### API Permissions ```yaml Microsoft Graph: - Sites.Read.All (Application) - Files.Read.All (Application) - offline_access (Delegated) Azure Service Management: - user_impersonation (Delegated) ``` ### Azure Roles ```yaml Scope: Azure AI Foundry Project Roles: - Azure AI Developer - Cognitive Services OpenAI User ``` ### Azure AI Foundry Agents ```yaml Agent 1 (Funciona): ID: asst_VwCt6zBWUkIhcqaFgiG9vUio Model: gpt-4o-mini Tools: [file_search] Vector Store: vs_OGPMUu5KbDHNgVE04xj2vkDq Agent 2 (Falla): ID: asst_6Ov3yAdqlTGOMEa4UzqRGobn Model: gpt-4o-mini Tools: [SharePoint] Connection: RAG_Sharepoint_Assitant ``` --- ## 🧪 Pruebas Realizadas ### ✅ Pruebas Exitosas 1. **Autenticación básica con ClientSecretCredential** - Funciona correctamente para `/ask2` - Token se obtiene sin problemas 2. **Azure AI Projects SDK** - Conexión exitosa al endpoint - Creación de threads y runs funciona 3. **File Search Tool** - Vector Store accesible - RAG funciona perfectamente ### ❌ Pruebas Fallidas 1. **SharePoint Tool con App-Only** - Error: "AppOnly OBO tokens not supported" - Falla en el momento de ejecutar el run 2. **Diferentes configuraciones de permisos** - Probamos Sites.Read.All, Files.Read.All - Ninguna combinación funciona con App-Only --- ## 📦 Información del Proyecto ### Dependencias NuGet ```xml ``` ### Configuración appsettings.json ```json { "AzureAIAgent": { "AzureAIProjectsEndpoint": "https://vicubo-service-ia.services.ai.azure.com/api/projects/vicubo-ia-chat-assistant", "AgentId": "asst_VwCt6zBWUkIhcqaFgiG9vUio", "Model": "gpt-4o-mini" }, "AzureAIAgentSharePoint": { "AzureAd": { "AgentId": "asst_6Ov3yAdqlTGOMEa4UzqRGobn", "TenantId": "2c4d6781-5a64-4cf2-b233-ced387dbebab", "ApplicationId": "cb2952e0-d4a2-4101-a868-734874f6790f", "ClientSecretValue": "XXXXXXXXXXXXXXXXXXXX", "SharePointConnectionName": "RAG_Sharepoint_Assitant" } } } ``` --- ## 🎯 Objetivo de la Consulta **Necesitamos confirmar:** 1. Si es una limitación conocida del SharePoint tool en Azure AI Foundry 2. Si existe una solución o workaround para usar Service Principal 3. Cuál es la arquitectura recomendada para nuestro caso de uso (API backend sin usuario interactivo) **Resultado esperado:** Poder consumir el endpoint `/api/drupal-ai/ask-sharepoint` de forma exitosa, similar a como funciona `/api/drupal-ai/ask2`. --- ## 📎 Archivos Adjuntos 1. **Program.cs** - Configuración de la aplicación 2. **DrupalAIController.cs** - Controlador con ambos endpoints 3. **AzureAIAgentService.cs** - Implementación del servicio 4. **appsettings.json** - Configuración (sin secretos reales) 5. **Logs completos** - De ambos endpoints (éxito y falla) --- ## 📞 Siguiente Paso Agradeceríamos orientación de Microsoft Support sobre: - La causa exacta del error "AppOnly OBO tokens not supported" - Alternativas para usar SharePoint tool con Service Principal - Mejores prácticas para implementar RAG con SharePoint en un servicio backend **Muchas gracias por su apoyo.** --- **Generado el**: 4 de noviembre de 2025 **Versión del documento**: 1.0