Skip to content

Commit a181380

Browse files
authored
Merge pull request #307443 from cephalin/openapi-secure
add foundry agent secure auth doc
2 parents 8046816 + b03e93e commit a181380

7 files changed

Lines changed: 151 additions & 10 deletions
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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)
111 KB
Loading

articles/app-service/toc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ items:
416416
href: configure-authentication-api-version.md
417417
- name: Use file-based configuration
418418
href: configure-authentication-file-based.md
419-
- name: MCP server authorization
420-
href: configure-authentication-mcp.md
419+
- name: Authenticate AI Foundry tool calls
420+
href: configure-authentication-ai-foundry-openapi-tool.md
421421
- name: Security and networking
422422
items:
423423
- name: Security overview

articles/app-service/tutorial-ai-integrate-azure-ai-agent-dotnet.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Integrate web app with OpenAPI in Azure AI Foundry Agent Service (.NET)
33
description: Empower your existing .NET web apps by integrating their capabilities into Azure AI Foundry Agent Service with OpenAPI, enabling AI agents to perform real-world tasks.
44
author: cephalin
55
ms.author: cephalin
6-
ms.date: 06/16/2025
6+
ms.date: 10/28/2025
77
ms.topic: tutorial
88
ms.custom:
99
- devx-track-dotnet
@@ -180,6 +180,9 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
180180
181181
1. In the **Define schema** page, paste the schema that you copied earlier. Review and save the action.
182182
183+
> [!TIP]
184+
> In this tutorial, the OpenAPI tool is configured to call your app anonymously without authentication. For production scenarios, you should secure the tool with managed identity authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md).
185+
183186
## Test the agent
184187
185188
1. If the agents playground isn't already opened in the foundry portal, select the agent and select **Try in playground**.
@@ -198,7 +201,7 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
198201
199202
When exposing APIs via OpenAPI in Azure App Service, follow these security best practices:
200203
201-
- **Authentication and Authorization**: Protect your OpenAPI endpoints in App Service behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
204+
- **Authentication and Authorization**: Protect your OpenAPI endpoints with Microsoft Entra authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md). You can also protect your endpoints behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
202205
- **Validate input data:** The sample code checks `ModelState.IsValid` in the `CreateTodo` method, which ensures that the incoming data matches the model's validation attributes. For more information, see [Model validation in ASP.NET Core](/aspnet/core/mvc/models/validation).
203206
- **Use HTTPS:** The sample relies on Azure App Service, which enforces HTTPS by default and provides free TLS/SSL certificates to encrypt data in transit.
204207
- **Limit CORS:** Restrict Cross-Origin Resource Sharing (CORS) to trusted domains only. For more information, see [Enable CORS](app-service-web-tutorial-rest-api.md#enable-cors).

articles/app-service/tutorial-ai-integrate-azure-ai-agent-java.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Integrate web app with OpenAPI in Azure AI Foundry Agent Service (Java)
33
description: Empower your existing Java web apps by integrating their capabilities into Azure AI Foundry Agent Service with OpenAPI, enabling AI agents to perform real-world tasks.
44
author: cephalin
55
ms.author: cephalin
6-
ms.date: 07/16/2025
6+
ms.date: 10/28/2025
77
ms.topic: tutorial
88
ms.custom:
99
- devx-track-java
@@ -132,6 +132,9 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
132132
133133
1. In the **Define schema** page, paste the schema that you copied earlier. Review and save the action.
134134
135+
> [!TIP]
136+
> In this tutorial, the OpenAPI tool is configured to call your app anonymously without authentication. For production scenarios, you should secure the tool with managed identity authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md).
137+
135138
## Test the agent
136139
137140
1. If the agents playground isn't already opened in the foundry portal, select the agent and select **Try in playground**.
@@ -150,7 +153,7 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
150153

151154
When exposing APIs via OpenAPI in Azure App Service, follow these security best practices:
152155

153-
- **Authentication and Authorization**: Protect your OpenAPI endpoints in App Service behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
156+
- **Authentication and Authorization**: Protect your OpenAPI endpoints with Microsoft Entra authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md). You can also protect your endpoints behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
154157
- **Validate and sanitize input data:** The example code in this tutorial omits input validation and sanitization for simplicity and clarity. In production scenarios, always implement proper validation and sanitization to protect your application. For Spring, see [Spring: Validating Form Input](https://spring.io/guides/gs/validating-form-input).
155158
- **Use HTTPS:** The sample relies on Azure App Service, which enforces HTTPS by default and provides free TLS/SSL certificates to encrypt data in transit.
156159
- **Limit CORS:** Restrict Cross-Origin Resource Sharing (CORS) to trusted domains only. For more information, see [Enable CORS](app-service-web-tutorial-rest-api.md#enable-cors).

articles/app-service/tutorial-ai-integrate-azure-ai-agent-node.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Integrate web app with OpenAPI in Azure AI Foundry Agent Service (Node.js
33
description: Empower your existing Node.js web apps by integrating their capabilities into Azure AI Foundry Agent Service with OpenAPI, enabling AI agents to perform real-world tasks.
44
author: cephalin
55
ms.author: cephalin
6-
ms.date: 07/21/2025
6+
ms.date: 10/28/2025
77
ms.topic: tutorial
88
ms.custom:
99
- devx-track-javascript
@@ -237,6 +237,9 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
237237
238238
1. In the **Define schema** page, paste the schema that you copied earlier. Review and save the action.
239239
240+
> [!TIP]
241+
> In this tutorial, the OpenAPI tool is configured to call your app anonymously without authentication. For production scenarios, you should secure the tool with managed identity authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md).
242+
240243
## Test the agent
241244
242245
1. If the agents playground isn't already opened in the foundry portal, select the agent and select **Try in playground**.
@@ -255,7 +258,7 @@ At a minimum, open the [sample application](https://github.com/Azure-Samples/msd
255258
256259
When exposing APIs via OpenAPI in Azure App Service, follow these security best practices:
257260
258-
- **Authentication and Authorization**: Protect your OpenAPI endpoints in App Service behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
261+
- **Authentication and Authorization**: Protect your OpenAPI endpoints with Microsoft Entra authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md). You can also protect your endpoints behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
259262
- **Validate input data:** Always validate incoming data to prevent invalid or malicious input. For Node.js apps, use libraries such as [express-validator](https://express-validator.github.io/docs/) to enforce data validation rules. Refer to their documentation for best practices and implementation details.
260263
- **Use HTTPS:** The sample relies on Azure App Service, which enforces HTTPS by default and provides free TLS/SSL certificates to encrypt data in transit.
261264
- **Limit CORS:** Restrict Cross-Origin Resource Sharing (CORS) to trusted domains only. For more information, see [Enable CORS](app-service-web-tutorial-rest-api.md#enable-cors).

articles/app-service/tutorial-ai-integrate-azure-ai-agent-python.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Integrate web app with OpenAPI in Azure AI Foundry Agent Service (Python)
33
description: Empower your existing Python web apps by integrating their capabilities into Azure AI Foundry Agent Service with OpenAPI, enabling AI agents to perform real-world tasks.
44
author: cephalin
55
ms.author: cephalin
6-
ms.date: 08/21/2025
6+
ms.date: 10/28/2025
77
ms.topic: tutorial
88
ms.custom:
99
- devx-track-python
@@ -147,6 +147,9 @@ FasAPI already contains OpenAPI functionality at the default path `/openapi.json
147147

148148
1. In the **Define schema** page, paste the schema that you copied earlier. Review and save the action.
149149

150+
> [!TIP]
151+
> In this tutorial, the OpenAPI tool is configured to call your app anonymously without authentication. For production scenarios, you should secure the tool with managed identity authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md).
152+
150153
## Test the agent
151154

152155
1. If the agents playground isn't already opened in the foundry portal, select the agent and select **Try in playground**.
@@ -163,7 +166,7 @@ FasAPI already contains OpenAPI functionality at the default path `/openapi.json
163166

164167
When exposing APIs via OpenAPI in Azure App Service, follow these security best practices:
165168

166-
- **Authentication and Authorization**: Protect your OpenAPI endpoints in App Service behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
169+
- **Authentication and Authorization**: Protect your OpenAPI endpoints with Microsoft Entra authentication. For step-by-step instructions, see [Secure OpenAPI endpoints for Azure AI Foundry Agent Service](configure-authentication-ai-foundry-openapi-tool.md). You can also protect your endpoints behind [Azure API Management with Microsoft Entra ID](/azure/api-management/api-management-howto-protect-backend-with-aad) and ensure only authorized users or agents can access the tools.
167170
- **Validate input data:** Always validate incoming data to prevent invalid or malicious input. For Python apps, use libraries such as [Pydantic](https://pypi.org/project/pydantic/) to enforce data validation rules with dedicated request schema models (such as RestaurantCreate and ReviewCreate). Refer to their documentation for best practices and implementation details.
168171
- **Use HTTPS:** The sample relies on Azure App Service, which enforces HTTPS by default and provides free TLS/SSL certificates to encrypt data in transit.
169172
- **Limit CORS:** Restrict Cross-Origin Resource Sharing (CORS) to trusted domains only. For more information, see [Enable CORS](app-service-web-tutorial-rest-api.md#enable-cors).

0 commit comments

Comments
 (0)