Skip to content

Commit a58fff4

Browse files
author
gitName
committed
wip
1 parent da082ab commit a58fff4

File tree

1 file changed

+94
-31
lines changed

1 file changed

+94
-31
lines changed
Lines changed: 94 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: Create OAuth application access to product - Azure API Management
33
titleSuffix: Azure API Management
4-
description: TBD
4+
description: Learn how to configure OAuth 2.0 application-based access to products in Azure API Management, including prerequisites and step-by-step guidance.
55
services: api-management
66
author: dlepow
77

88
ms.service: azure-api-management
99
ms.topic: how-to
10-
ms.date: 05/02/2025
10+
ms.date: 05/06/2025
1111
ms.author: danlep
1212
ms.custom:
1313
---
@@ -16,25 +16,33 @@ ms.custom:
1616

1717
[!INCLUDE [api-management-availability-premium-dev-standard-basic](../../includes/api-management-availability-premium-dev-standard-basic.md)]
1818

19-
[Intro here]
19+
API Management is introducing built-in OAuth 2.0 application-based access to products using the client credentials flow.
2020

21+
With this feature, an API manager configures an application in Microsoft Entra ID to represent a product, and registers a client application in Microsoft Entra ID that restricts access to the product's APIs. A developer (or client app) can then use the OAuth 2.0 client credentials flow to obtain OAuth tokens from the client application that are passed to the API Management gateway for authorization to the product's APIs.
2122

22-
Applications feature is now available for private preview testing.
23+
> [!NOTE]
24+
> This feature is in private preview. Ensure that you have received instructions to access the preview and that your subscription allows you to create an API Management instance in an Early Updates Access Program (EUAP) region. See detailed [Prerequisites](#prerequisites).
25+
>
2326
27+
This article describes the following steps:
2428

25-
> [!NOTE]
26-
> This feature is in private preview. Ensure that you have ...
29+
* Enable application-based access for a product in API Management.
30+
* Create a client application in API Management that restricts access to the product.
31+
* Test OAuth 2.0 token-based access the product's associated API.
32+
* View the client application in the developer portal and get secure access to the product's APIs.
2733

34+
<!-- Clarify personas
2835
This feature enables:
2936
3037
* API Management gateway can now authorize product/API access using OAuth token **in client credentials flow**
3138
* API managers can identify products which have OAuth authorization enabled
3239
* API managers can create client applications and assign access to products
3340
* Developers can view all client applications and use OAuth token to get secure access to product/API
41+
-->
3442

3543
## Prerequisites
3644

37-
- An API Management instance deployed in one of the Azure Early Updates Access Program (EUAP) regions, such as Central US EUAP. If you haven't yet created an API Management service instance, see [Create an API Management service instance](get-started-create-service-instance). The API Management instance must be in **Premium**, **Standard**, **Basic**, or **Developer** tier.
45+
- An API Management instance deployed in one of the Azure Early Updates Access Program (EUAP) regions, such as Central US EUAP. To create an API Management service instance, see [Create an API Management service instance](get-started-create-service-instance.md). The API Management instance must be in **Premium**, **Standard**, **Basic**, or **Developer** tier.
3846

3947
> [!NOTE]
4048
> If you don't have access to an EUAP region, you can [request it](/troubleshoot/azure/general/region-access-request-process) through the Azure portal.
@@ -45,20 +53,14 @@ This feature enables:
4553

4654
- Permissions to assign the **Application Administrator** role, which requires at least the **Privileged Role Administrator** role in Microsoft Entra.
4755

48-
- Optionally, one or more [users](api-management-howto-create-or-invite-developers.md) in your API Management instance.
49-
50-
51-
[Any special considerations to access the preview - regions, special URLs, etc.]
56+
- Optionally, add one or more [users](api-management-howto-create-or-invite-developers.md) in your API Management instance.
5257

53-
## Scenario overview
58+
[!INCLUDE [azure-powershell-requirements-no-header](~/reusable-content/ce-skilling/azure/includes/azure-powershell-requirements-no-header.md)]
5459

55-
The following are the high level configuration steps:
5660

57-
1. Register an application ...in Microsoft Entra ID.
61+
<!-- Any special considerations to access the preview - regions, special URLs, etc. -->
5862

59-
1. The developer portal requests a token from Microsoft Entra ID using the client-app credentials.
6063

61-
1. After successful validation, Microsoft Entra ID issues the access/refresh token.
6264

6365

6466
<!-- Clarify personas for API Management and developer portal. -->
@@ -77,71 +79,132 @@ The following are the high level configuration steps:
7779
1. In the left menu, select **Manage** > **Roles and administrators**.
7880
1. Select **Application administrator**.
7981
1. In the left menu, select **Manage** > **Assignments** > **+ Add assignments**.
80-
1. In the **Add assignments** pane, search for the API Management instance's managed identity by name or object (prinicipal) ID, select it, and then select **Add**.
82+
1. In the **Add assignments** pane, search for the API Management instance's managed identity by name or object (principal) ID, select it, and then select **Add**.
8183

8284

8385
## Enable application based access for product
8486

85-
Follow these steps to enable **Application based access** for a product:
87+
Follow these steps to enable **Application based access** for a product. Enabling this setting automatically creates an application in Microsoft Entra ID to represent the selected product.
88+
8689

8790
1. Sign in to the [Azure portal](https://portal.azure.com) and navigate to your API Management instance.
8891
2. In the left menu, under **APIs**, select **Products**.
8992
3. Choose the product you want to configure, such as the **Starter** product.
9093
4. In the left menu, under **Product**, select **Properties**.
9194
5. Enable the **Application based access** setting.
92-
6. Click **Save**.
93-
94-
Enabling this setting automatically creates a client application in Microsoft Entra ID for the selected product.
95+
6. Select **Save**.
9596

9697
:::image type="content" source="media/applications/enable-application-based-access.png" alt-text="Screenshot of enabling application based access in the portal.":::
9798

9899
> [!TIP]
99100
> You can also enable the **Application based access** setting when creating a new product.
100101
101-
### Review application settings
102+
## Review product application settings
102103

103104
After you enable application based access, an enterprise application is created.
104105

105106
The application is named with the following format: **APIMProductApplication<product-name>**. For example, if the product name is **Starter**, the application name is **APIMProductApplicationStarter**. The application should have an **App role** defined.
106107

107108
You can review application settings in **App registrations**.
108109

109-
1. Sign in to the Azure portal and naviage to **App registrations**.
110+
1. Sign in to the Azure portal and navigate to **App registrations**.
110111
1. Select **All applications** and search for the application created by API Management.
111112
1. In the left menu, under **Manage**, select **App roles**.
112113
1. Confirm that an application role was set by Azure API Management, as shown in the following screenshot:
113114

114115
:::image type="content" source="media/applications/application-roles.png" alt-text="Screenshot of app roles in the portal.":::
115116

116-
## Create application for multiple products
117+
## Create client application to access product
118+
119+
Now create a client application that will be registered in Microsoft Entra ID and restricts to access one or more products.
117120

118-
You can also create an application directly in the portal that can access multiple products. Products must have **Application based access** enabled to have the application access them.
121+
* Products must have **Application based access** enabled to be associated with a client application.
122+
* Each client application is associated with a single user (owner) in the API Management instance.
123+
* A product can be associated with more than one client application.
119124

120125
1. Sign in to the Azure portal at the following URL (`https://portal.azure.com/?showversion=true&feature.customPortal=false&Microsoft_Azure_ApiManagement=javierbo2&applicationNewRoleValueFormat=true`) and navigate to your API Management instance.
121126
1. In the left menu, under **APIs**, select **Applications** > **+ Register application**.
122-
1. In the **Register an application** pane,
123-
1. Enter the following application settings:
127+
1. In the **Register an application** pane, enter the following application settings:
124128
* **Name**: Enter a name for the application.
125-
* **Owner**: Select the owner of the application from the dropdown list. This list includes all users in the API Management instance.
126-
* **Grant access to selected products**: Select one or more products that you want the application to access. You can select one or more products in the API Management instance that have **Application based access** enabled.
129+
* **Owner**: Select the owner of the application from the dropdown list of users in the API Management instance.
130+
* **Grant access to selected products**: Select one or more products in the API Management instance that have **Application based access** enabled, such as the **Starter** product (see [Enable application based access for product](#enable-application-based-access-for-product)).
127131
* **Description**: Optionally enter a description.
128132

129133
:::image type="content" source="media/applications/register-application.png" alt-text="Screenshot of application settings in the portal.":::
130134
1. Select **Register**.
131135

136+
The application is added to the list of applications on the Applications pane. A client secret is automatically generated for the application. The client secret is used to obtain an OAuth token from the client application in the client credentials flow.
132137

133-
<!-- Should the application then appear in the list of applications? -->
138+
<!-- Where would client secret show? Should customer store it somewhere? -->
134139

140+
## Review client application settings
135141

142+
Review the settings for the client application in Microsoft Entra ID.
136143

137-
## Add/remove products in application
144+
The application is named with the following format: **xxxxxxTBD**. For example, if the product name is **Starter**, the application name is **APIMProductApplicationStarter**. The application should have an **App role** defined.
138145

146+
You can review application settings in **App registrations**.
147+
148+
1. Sign in to the Azure portal and navigate to **App registrations**.
149+
1. Select **All applications** and search for the application created by API Management.
150+
1. In the left menu, under **Manage**, select **App roles**.
151+
1. Confirm that an application role was set by Azure API Management, as shown in the following screenshot:
139152

140153

141154
## Create token and use with API call
142155

156+
157+
Run the following Azure PowerShell scripts to obtain a token generated for the client application and to call a product API using the token.
158+
159+
<!-- Warn about secure handling of token and secrets -->
160+
161+
### Obtain token for client application
162+
```powershell
163+
164+
# Replace placeholder values with your own values.
165+
166+
$clientId = "aa8029d8-83a5-4713-939d-cebac1bbd672" # Client (application) ID of client application
167+
$clientSecret = "xxxxx" # Retrieve secret of client application in developer portal
168+
$scopeOfOtherApp = "api://03db2e9e-efe9-4f68-b74d-911966d1a684/.default" # Audience of application audience is visible under a product
169+
$tenantId = "e74bd0b5-f803-4e01-858b-dba7e58e55cf" # Your tenant id
170+
171+
$body = @{
172+
    grant_type    = "client_credentials"
173+
    client_id     = $clientId
174+
    client_secret = $clientSecret
175+
    scope         = $scopeOfOtherApp
176+
}
177+
$response = Invoke-RestMethod -Method Post -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -ContentType "application/x-www-form-urlencoded" -Body $body
178+
$token = $response.access_token
179+
$token
180+
```
181+
182+
### Call product API using token
183+
184+
The token generated in the previous step is used to call a product API. The token is passed in the **Authorization** header of the request. The API Management instance validates the token and authorizes access to the API.
185+
186+
```powershell
187+
188+
# $token = "...token here..."
189+
# Gatewate endpoint to call. Update with URI of API operation you want to call.
190+
$uri = "https://<gateway-hostname>/echo/resource?param1=sample"
191+
#
192+
$headers = @{
193+
   "Authorization" = "Bearer $token"
194+
}
195+
$body = @{
196+
    "hello" = "world"
197+
} | ConvertTo-Json -Depth 5
198+
$getresponse = Invoke-RestMethod -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Headers $headers -Body $body
199+
Write-Host "Response:"
200+
$getresponse | ConvertTo-Json -Depth 5
201+
```
202+
203+
143204
## List applications and get secrets in the developer portal
144205

145206

146207
## Related content
147208

209+
* Add link here
210+

0 commit comments

Comments
 (0)