|
| 1 | +--- |
| 2 | +title: Secure OpenAPI tool calls from Azure AI Foundry Agent Service |
| 3 | +description: Configure Microsoft Entra authentication to secure Azure AI Foundry tool calls with managed identity, step by step. |
| 4 | +ms.topic: how-to |
| 5 | +ms.date: 10/28/2025 |
| 6 | +author: cephalin |
| 7 | +ms.author: cephalin |
| 8 | +ms.service: azure-app-service |
| 9 | +ms.collection: ce-skilling-ai-copilot |
| 10 | +--- |
| 11 | + |
| 12 | +# Secure OpenAPI endpoints for Azure AI Foundry Agent Service |
| 13 | + |
| 14 | +This article shows you how to secure your App Service OpenAPI endpoints when they're called by Azure AI Foundry Agent Service. When you add your App Service app as an OpenAPI tool in Azure AI Foundry, you can configure it to call your APIs anonymously without authentication, which is easier for development and testing. However, for production environments, you should use Microsoft Entra authentication with managed identity. This guide walks you through configuring managed identity authentication to enable secure, token-based communication between Azure AI Foundry and your app. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- An App Service app with OpenAPI endpoints. If you need to add OpenAPI functionality to your app, see one of the following tutorials: |
| 19 | + - [Add an App Service app as a tool in Azure AI Foundry Agent Service (.NET)](tutorial-ai-integrate-azure-ai-agent-dotnet.md) |
| 20 | + - [Add an App Service app as a tool in Azure AI Foundry Agent Service (Java)](tutorial-ai-integrate-azure-ai-agent-java.md) |
| 21 | + - [Add an App Service app as a tool in Azure AI Foundry Agent Service (Python)](tutorial-ai-integrate-azure-ai-agent-python.md) |
| 22 | + - [Add an App Service app as a tool in Azure AI Foundry Agent Service (Node.js)](tutorial-ai-integrate-azure-ai-agent-node.md) |
| 23 | + |
| 24 | +- An Azure AI Foundry project where you'll add your app as an OpenAPI tool. |
| 25 | + |
| 26 | +## Find your Azure AI Foundry project's managed identity IDs |
| 27 | + |
| 28 | +You need both the object ID and the application ID of your Azure AI Foundry project's managed identity to configure App Service authentication. A system-assigned managed identity is automatically created for your Azure AI Foundry project when you create it. This identity is what Azure AI Foundry Agent Service uses to authenticate with your app. |
| 29 | + |
| 30 | +1. In the [Azure AI Foundry portal](https://ai.azure.com), navigate to your project and select **Overview**. |
| 31 | + |
| 32 | +1. In the **Project details** section on the right, select the link next to **Resource group** to open the resource group in the Azure portal. |
| 33 | + |
| 34 | +1. In the resource group, find and select your AI Foundry project resource. |
| 35 | + |
| 36 | +1. In the project resource's left menu, select **Resource Management** > **Identity**. |
| 37 | + |
| 38 | +1. Under **System assigned**, copy the value of **Object (principal) ID** for later. |
| 39 | + |
| 40 | +1. In the Azure portal, search for and select **Microsoft Entra ID**. |
| 41 | + |
| 42 | +1. In the search box, search for the object ID you copied and select it in the search results. |
| 43 | + |
| 44 | +1. On the **Overview** page, copy the value of **Application ID**. |
| 45 | + |
| 46 | + Note the **Object ID** is the same as the one shown in the system-assigned managed identity. You need both the application ID and the object ID for configuring App Service authentication. |
| 47 | + |
| 48 | +## Configure Microsoft Entra authentication for your app |
| 49 | + |
| 50 | +1. In the Azure portal, navigate to your App Service app. |
| 51 | + |
| 52 | +1. On your app's left menu, select **Settings** > **Authentication**, and then select **Add identity provider**. |
| 53 | + |
| 54 | +1. On the **Add an identity provider** page, select **Microsoft** as the **Identity provider** to create a new app registration. |
| 55 | + |
| 56 | +1. Under **Additional checks**, for **Client application requirement**, select **Allow requests from specific client applications**. |
| 57 | + |
| 58 | +1. Select the pencil widget and add the **application ID** that you copied in [Find your Azure AI Foundry project's managed identity IDs](#find-your-azure-ai-foundry-projects-managed-identity-ids). |
| 59 | + |
| 60 | +1. For **Identity requirement**, select **Allow requests from specific identities**. |
| 61 | + |
| 62 | +1. Select the pencil widget and add the **object ID** that you copied in [Find your Azure AI Foundry project's managed identity IDs](#find-your-azure-ai-foundry-projects-managed-identity-ids). |
| 63 | + |
| 64 | +1. For **Tenant requirement** accept the default value. If not, be sure to select the tenant where your Azure AI Foundry project (or rather its identity) is created. |
| 65 | + |
| 66 | +1. For **Unauthenticated requests**, select **HTTP 401 Unauthorized: recommended for APIs**. |
| 67 | + |
| 68 | +1. Select **Add** to create the identity provider. |
| 69 | + |
| 70 | + :::image type="content" source="media/configure-authentication-ai-foundry-openapi-tool/entra-auth-configuration.png" alt-text="Screenshot showing the configuration of a new Microsoft authentication provider in the App Service."::: |
| 71 | + |
| 72 | +## Update the app registration Application ID URI |
| 73 | + |
| 74 | +After enabling authentication, you need to update the app registration's Application ID URI to match your App Service app's URL. |
| 75 | + |
| 76 | +1. After the Microsoft provider configuration completes, select it in the **Identity provider** column to open the app registration page. |
| 77 | + |
| 78 | +1. In the left menu, select **Manage** > **Expose an API**. |
| 79 | + |
| 80 | +1. Next to **Application ID URI**, select **Edit**. |
| 81 | + |
| 82 | +1. Change the value to your App Service app's URL in the following format: `https://<suffix>.azurewebsites.net`. |
| 83 | + |
| 84 | + You can find the app's hostname on the **Overview** page in **Default domain**. |
| 85 | + |
| 86 | +1. Select **Save**. |
| 87 | + |
| 88 | +> [!WARNING] |
| 89 | +> If you delete your App Service app, you must also delete the app registration and clean up any authentication resources that reference the Application ID URI. Failing to do so creates a security vulnerability: if someone else creates an app with the same URL, they could potentially gain unauthorized access to resources that trust the orphaned app registration. Always remove app registrations and their associated permissions when decommissioning an app. |
| 90 | +
|
| 91 | +## Configure the OpenAPI tool in Azure AI Foundry |
| 92 | + |
| 93 | +> [!NOTE] |
| 94 | +> This section assumes you already completed one of the tutorials in the [Prerequisites](#prerequisites) section, where you added your app as an OpenAPI tool in Azure AI Foundry using anonymous authentication. You now update the tool to use managed identity authentication. |
| 95 | +
|
| 96 | +1. Back in the [Azure AI Foundry portal](https://ai.azure.com), select your agent. |
| 97 | + |
| 98 | +1. Find the OpenAPI tool and select it to edit. |
| 99 | + |
| 100 | +1. In the **Define the schema for this tool** page: |
| 101 | + |
| 102 | + 1. Paste your OpenAPI schema. For more information, see [How to use OpenAPI with Azure AI Foundry Agent Service](/azure/ai-services/agents/how-to/tools/openapi-spec). |
| 103 | + |
| 104 | + 1. For **Authentication method**, select **Managed Identity**. |
| 105 | + |
| 106 | + 1. For **Audience**, enter your App Service app's URL. This URL must match the **Application ID URI** that you configured earlier. |
| 107 | + |
| 108 | + > [!TIP] |
| 109 | + > Azure AI Foundry Agent Service uses the system-assigned managed identity to authenticate with your app. Because you added the identity's client ID as an allowed client application and an allowed identity in your app's authentication provider configuration, the agent service is authorized to call your app's APIs. |
| 110 | +
|
| 111 | +1. Review and save the tool. |
| 112 | + |
| 113 | +## Test the agent |
| 114 | + |
| 115 | +1. In the Azure AI Foundry portal, select your agent and select **Try in playground**. |
| 116 | + |
| 117 | +1. Chat with the agent to test your OpenAPI endpoints. For example: |
| 118 | + |
| 119 | + - Show me all the tasks. |
| 120 | + - Create a task called "Buy groceries." |
| 121 | + - Update that task to "Buy groceries and cook dinner." |
| 122 | + |
| 123 | +If the authentication is configured correctly, the agent successfully calls your app's APIs through the OpenAPI tool. |
| 124 | + |
| 125 | +## Related content |
| 126 | + |
| 127 | +- [Configure your App Service or Azure Functions app to use Microsoft Entra sign-in](configure-authentication-provider-aad.md) |
| 128 | +- [Integrate AI into your Azure App Service applications](overview-ai-integration.md) |
| 129 | +- [What is Azure AI Foundry Agent Service?](/azure/ai-services/agents/overview) |
0 commit comments