You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/api-management/api-management-howto-oauth2.md
+55-43Lines changed: 55 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,9 @@ author: dlepow
8
8
9
9
ms.service: api-management
10
10
ms.topic: article
11
-
ms.date: 04/26/2022
11
+
ms.date: 11/09/2022
12
12
ms.author: danlep
13
+
ms.custom: engagement-fy23
13
14
---
14
15
15
16
# How to authorize test console of developer portal by configuring OAuth 2.0 user authorization
@@ -30,7 +31,7 @@ If you haven't yet created an API Management service instance, see [Create an AP
30
31
31
32
Configuring OAuth 2.0 user authorization in API Management only enables the developer portal’s test console as a client to acquire a token from the authorization server. The configuration for each OAuth 2.0 provider is different, although the steps are similar, and the required pieces of information used to configure OAuth 2.0 in your API Management service instance are the same. This article shows an example using Azure Active Directory as an OAuth 2.0 provider.
32
33
33
-
:::image type="content" source="media/api-management-howto-oauth2/overview-graphic-azure-ad.png" alt-text="Overview graphic to visually conceptualize the following flow.":::
34
+
The following are the high level configuration steps:
34
35
35
36
1. Register an application (backend-app) in Azure AD to represent the API.
36
37
@@ -42,7 +43,22 @@ Configuring OAuth 2.0 user authorization in API Management only enables the deve
42
43
43
44
1. Configure an API to use OAuth 2.0 user authorization.
44
45
45
-
1. Add the **validate-jwt** policy to pre-authorize the OAuth 2.0 token for every incoming request.
46
+
1. Add a policy to pre-authorize the OAuth 2.0 token for every incoming request. You can use the `validate-jwt` policy for any OAuth 2.0 provider.
47
+
48
+
This configuration supports the following OAuth flow:
49
+
50
+
:::image type="content" source="media/api-management-howto-oauth2/overview-graphic-azure-ad.png" alt-text="Overview graphic to visually conceptualize the following flow.":::
51
+
52
+
1. The developer portal requests a token from Azure AD using the client-app credentials.
53
+
54
+
1. After successful validation, Azure AD issues the access/refresh token.
55
+
56
+
1. A developer (user of the developer portal) makes an API call with the authorization header.
57
+
58
+
1. The token gets validated by using the `validate-jwt` policy in API Management by Azure AD.
59
+
60
+
1. Based on the validation result, the developer will receive the response in the developer portal.
61
+
46
62
47
63
## Authorization grant types
48
64
@@ -82,14 +98,10 @@ Throughout this tutorial you'll be asked to record key information to reference
82
98
83
99
You'll need to register two applications with your OAuth 2.0 provider: one represents the backend API to be protected, and a second represents the client application that calls the API - in this case, the test console of the developer portal.
84
100
85
-
The following are example steps using Azure AD as the OAuth 2.0 provider.
101
+
The following are example steps using Azure AD as the OAuth 2.0 provider. For details about app registration, see [Quickstart: Configure an application to expose a web API](../active-directory/develop/quickstart-configure-app-expose-web-apis.md).
86
102
87
103
### Register an application in Azure AD to represent the API
88
104
89
-
Using the Azure portal, register an application that represents the backend API in Azure AD.
90
-
91
-
For details about app registration, see [Quickstart: Configure an application to expose a web API](../active-directory/develop/quickstart-configure-app-expose-web-apis.md).
92
-
93
105
1. In the [Azure portal](https://portal.azure.com), search for and select **App registrations**.
94
106
95
107
1. Select **New registration**.
@@ -108,7 +120,9 @@ For details about app registration, see [Quickstart: Configure an application to
108
120
1. Under the **Manage** section of the side menu, select **Expose an API** and set the **Application ID URI** with the default value. Record this value for later.
109
121
110
122
1. Select the **Add a scope** button to display the **Add a scope** page:
111
-
1. Enter a new **Scope name**, **Admin consent display name**, and **Admin consent description**.
123
+
1. Enter a **Scope name** for a scope that's supported by the API (for example, **Files.Read**).
124
+
1. In **Who can consent?**, make a selection for your scenario, such as **Admins and users**. Select **Admins only** for higher privileged scenarios.
125
+
1. Enter **Admin consent display name** and **Admin consent description**.
112
126
1. Make sure the **Enabled** scope state is selected.
113
127
114
128
1. Select the **Add scope** button to create the scope.
@@ -119,9 +133,7 @@ For details about app registration, see [Quickstart: Configure an application to
119
133
120
134
### Register another application in Azure AD to represent a client application
121
135
122
-
Register every client application that calls the API as an application in Azure AD. In this example, the client application is the **test console** in the API Management developer portal.
123
-
124
-
To register an application in Azure AD to represent the client application:
136
+
Register every client application that calls the API as an application in Azure AD.
125
137
126
138
1. In the [Azure portal](https://portal.azure.com), search for and select **App registrations**.
127
139
@@ -130,9 +142,9 @@ To register an application in Azure AD to represent the client application:
130
142
1. When the **Register an application page** appears, enter your application's registration information:
131
143
132
144
- In the **Name** section, enter a meaningful application name that will be displayed to users of the app, such as *client-app*.
133
-
- In the **Supported account types** section, select **Accounts in any organizational directory (Any Azure AD directory - Multitenant)**.
145
+
- In the **Supported account types** section, select an option that suits your scenario.
134
146
135
-
1. In the **Redirect URI** section, select `Web` and leave the URL field empty for now.
147
+
1. In the **Redirect URI** section, select **Web** and leave the URL field empty for now.
136
148
137
149
1. Select **Register** to create the application.
138
150
@@ -141,7 +153,7 @@ To register an application in Azure AD to represent the client application:
141
153
1. Create a client secret for this application to use in a subsequent step.
142
154
143
155
1. Under the **Manage** section of the side menu, select **Certificates & secrets**.
144
-
1. Under **Client secrets**, select **New client secret**.
156
+
1. Under **Client secrets**, select **+ New client secret**.
145
157
1. Under **Add a client secret**, provide a **Description** and choose when the key should expire.
146
158
1. Select **Add**.
147
159
@@ -172,9 +184,9 @@ Optionally:
172
184
173
185
1. In the [Azure portal](https://portal.azure.com), navigate to your API Management instance.
174
186
175
-
1. Under the Developer portal section in the side menu, select **OAuth 2.0 + OpenID Connect**.
187
+
1. Under **Developer portal** in the side menu, select **OAuth 2.0 + OpenID Connect**.
1. The next section of the form contains the **Authorization grant types**, **Authorization endpoint URL**, and **Authorization request method** settings.
193
205
194
-
* Select one or more desired **Authorization grant types**. For this example, select **Authorization code** (the default). [Learn more](#authorization-grant-types).
206
+
* Select one or more desired **Authorization grant types**. For this example, select **Authorization code** (the default). [Learn more](#authorization-grant-types)
195
207
196
-
* Enter the **Authorization endpoint URL**. For Azure AD, this URL will be similar to one of the following URLs, where `<tenant_id>` is replaced with the ID of your Azure AD tenant. You can obtain the endpoint URL from the **Endpoints** page of one of your app registrations.
208
+
* Enter the **Authorization endpoint URL**. You can obtain the endpoint URL from the **Endpoints** page of one of your app registrations. For a single-tenant app in Azure AD, this URL will be similar to one of the following URLs, where `{aad-tenant}` is replaced with the ID of your Azure AD tenant.
197
209
198
210
Using the v2 endpoint is recommended; however, API Management supports both v1 and v2 endpoints.
* Enter the **Token endpoint URL**. For Azure AD, it will be similar to one of the following URLs, where `<tenant_id>` is replaced with the ID of your Azure AD tenant. Use the same endpoint version (v2 or v1) that you chose previously.
222
+
* Enter the **Token endpoint URL**. For a single tenant app in Azure AD, it will be similar to one of the following URLs, where `{aad-tenant}` is replaced with the ID of your Azure AD tenant. Use the same endpoint version (v2 or v1) that you chose previously.
* If you use **v1** endpoints, add a body parameter:
217
229
* Name: **resource**.
@@ -222,29 +234,29 @@ Optionally:
222
234
223
235
* Accept the default settings for **Client authentication methods** and **Access token sending method**.
224
236
225
-
1.The**Client credentials** section contains the **Client ID** and **Client secret**, which you obtained during the creation and configuration process of your client-app.
237
+
1.In**Client credentials**, enter the **Client ID** and **Client secret**, which you obtained during the creation and configuration process of your client-app.
226
238
227
239
1. After the **Client ID** and **Client secret** are specified, the **Redirect URI** for the **authorization code** is generated. This URI is used to configure the redirect URI in your OAuth 2.0 server configuration.
228
240
229
241
In the developer portal, the URI suffix is of the form:
230
242
231
243
-`/signin-oauth/code/callback/{authServerName}` for authorization code grant flow
232
244
-`/signin-oauth/implicit/callback` for implicit grant flow
233
-
234
-
Copy the appropriate Redirect URI to the **Authentication** page of your client-app registration.
235
245
236
246
:::image type="content" source="media/api-management-howto-oauth2/oauth-04.png" alt-text="Add client credentials for the OAuth 2.0 service":::
237
247
248
+
Copy the appropriate Redirect URI to the **Authentication** page of your client-app registration. In the app registration, select **Authentication** > **+ Add a platform** > **Web**, and then enter the Redirect URI.
249
+
238
250
1. If **Authorization grant types** is set to **Resource owner password**, the **Resource owner password credentials** section is used to specify those credentials; otherwise you can leave it blank.
239
251
240
252
1. Select **Create** to save the API Management OAuth 2.0 authorization server configuration.
241
253
242
254
1.[Republish](api-management-howto-developer-portal-customize.md#publish) the developer portal.
243
255
244
-
> [!NOTE]
245
-
> When making OAuth 2.0-related changes, it is important that you remember to (re-)publish the developer portal after every modification as relevant changes (for example, scope change) otherwise cannot propagate into the portal and subsequently be used in trying out the APIs.
256
+
> [!IMPORTANT]
257
+
> When making OAuth 2.0-related changes, be sure to to republish the developer portal after every modification as relevant changes (for example, scope change) otherwise cannot propagate into the portal and subsequently be used in trying out the APIs.
246
258
247
-
After saving the OAuth 2.0 server configuration, configure APIs to use this configuration, as shown in the next section.
259
+
After saving the OAuth 2.0 server configuration, configure an API or APIs to use this configuration, as shown in the next section.
248
260
249
261
## Configure an API to use OAuth 2.0 user authorization
250
262
@@ -256,25 +268,33 @@ After saving the OAuth 2.0 server configuration, configure APIs to use this conf
## Configure a JWT validation policy to pre-authorize requests
276
+
277
+
In the configuration so far, API Management doesn't validate the access token. It only passes the token in the authorization header to the backend API.
278
+
279
+
To pre-authorize requests, configure a [validate-jwt](api-management-access-restriction-policies.md#ValidateJWT) policy to validate the access token of each incoming request. If a request doesn't have a valid token, API Management blocks it.
Once you've configured your OAuth 2.0 authorization server and configured your API to use that server, you can test it by going to the developer portal and calling an API. Click**Developer portal (legacy)** in the top menu from your Azure API Management instance **Overview** page.
288
+
Once you've configured your OAuth 2.0 authorization server and configured your API to use that server, you can test it by going to the developer portal and calling an API. Select**Developer portal (legacy)** in the top menu from your Azure API Management instance **Overview** page.
269
289
270
-
Click**APIs** in the top menu and select **Echo API**.
290
+
Select**APIs** in the top menu and select **Echo API**.
271
291
272
292
![Echo API][api-management-apis-echo-api]
273
293
274
294
> [!NOTE]
275
295
> If you have only one API configured or visible to your account, then clicking APIs takes you directly to the operations for that API.
276
296
277
-
Select the **GET Resource** operation, click**Open Console**, and then select **Authorization code** from the drop-down.
297
+
Select the **GET Resource** operation, select**Open Console**, and then select **Authorization code** from the drop-down.
278
298
279
299
![Open console][api-management-open-console]
280
300
@@ -291,14 +311,6 @@ Once you've signed in, the **Request headers** are populated with an `Authorizat
291
311
292
312
At this point you can configure the desired values for the remaining parameters, and submit the request.
293
313
294
-
## Configure a JWT validation policy to pre-authorize requests
295
-
296
-
In the preceding section, API Management doesn't validate the access token. It only passes the token in the authorization header to the backend API.
297
-
298
-
To pre-authorize requests, configure a [validate-jwt](api-management-access-restriction-policies.md#ValidateJWT) policy to validate the access token of each incoming request. If a request doesn't have a valid token, API Management blocks it.
For more information about using OAuth 2.0 and API Management, see [Protect a web API backend in Azure API Management using OAuth 2.0 authorization with Azure Active Directory](api-management-howto-protect-backend-with-aad.md).
Copy file name to clipboardExpand all lines: includes/api-management-configure-validate-jwt.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ ms.author: danlep
8
8
9
9
The following example policy, when added to the `<inbound>` policy section, checks the value of the audience claim in an access token obtained from Azure AD that is presented in the Authorization header. It returns an error message if the token is not valid. Configure this policy at a policy scope that's appropriate for your scenario.
10
10
11
-
* In `openid-config`, the `aad-tenant` is the tenant ID in Azure AD. Find this value in the Azure portal, for example, on the **Overview** page of your Azure AD resource.
11
+
* In the `openid-config` URL, the `aad-tenant` is the tenant ID in Azure AD. Find this value in the Azure portal, for example, on the **Overview** page of your Azure AD resource. The example shown assumes a single-tenant Azure AD app and a v2 configuration endpoint.
12
12
* The value of the `claim` is the client ID of the backend-app you registered in Azure AD.
13
13
14
14
@@ -24,6 +24,6 @@ The following example policy, when added to the `<inbound>` policy section, chec
24
24
```
25
25
26
26
> [!NOTE]
27
-
> The preceding `openid-config` URL corresponds to the v2 endpoint. For the v1 `openid-config`endpoint, use `https://login.microsoftonline.com/{aad-tenant}/.well-known/openid-configuration`.
27
+
> The preceding `openid-config` URL corresponds to the v2 endpoint. For the v1 `openid-config`endpoint, use `https://login.microsoftonline.com/{aad-tenant}/.well-known/openid-configuration`.
28
28
29
29
For information on how to configure policies, see [Set or edit policies](../articles/api-management/set-edit-policies.md).
0 commit comments