Skip to content

Commit ea888d6

Browse files
authored
Merge pull request #217870 from dlepow/odpfresh
[APIM] Dev portal OAuth - freshness
2 parents af8090a + ca5ce80 commit ea888d6

File tree

4 files changed

+58
-46
lines changed

4 files changed

+58
-46
lines changed

articles/api-management/api-management-howto-oauth2.md

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ author: dlepow
88

99
ms.service: api-management
1010
ms.topic: article
11-
ms.date: 04/26/2022
11+
ms.date: 11/09/2022
1212
ms.author: danlep
13+
ms.custom: engagement-fy23
1314
---
1415

1516
# 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
3031

3132
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.
3233

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:
3435

3536
1. Register an application (backend-app) in Azure AD to represent the API.
3637

@@ -42,7 +43,22 @@ Configuring OAuth 2.0 user authorization in API Management only enables the deve
4243

4344
1. Configure an API to use OAuth 2.0 user authorization.
4445

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+
4662

4763
## Authorization grant types
4864

@@ -82,14 +98,10 @@ Throughout this tutorial you'll be asked to record key information to reference
8298

8399
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.
84100

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).
86102

87103
### Register an application in Azure AD to represent the API
88104

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-
93105
1. In the [Azure portal](https://portal.azure.com), search for and select **App registrations**.
94106

95107
1. Select **New registration**.
@@ -108,7 +120,9 @@ For details about app registration, see [Quickstart: Configure an application to
108120
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.
109121

110122
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**.
112126
1. Make sure the **Enabled** scope state is selected.
113127

114128
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
119133

120134
### Register another application in Azure AD to represent a client application
121135

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.
125137

126138
1. In the [Azure portal](https://portal.azure.com), search for and select **App registrations**.
127139

@@ -130,9 +142,9 @@ To register an application in Azure AD to represent the client application:
130142
1. When the **Register an application page** appears, enter your application's registration information:
131143

132144
- 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.
134146

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.
136148

137149
1. Select **Register** to create the application.
138150

@@ -141,7 +153,7 @@ To register an application in Azure AD to represent the client application:
141153
1. Create a client secret for this application to use in a subsequent step.
142154

143155
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**.
145157
1. Under **Add a client secret**, provide a **Description** and choose when the key should expire.
146158
1. Select **Add**.
147159

@@ -172,9 +184,9 @@ Optionally:
172184

173185
1. In the [Azure portal](https://portal.azure.com), navigate to your API Management instance.
174186

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**.
176188

177-
1. Under the **OAuth 2.0 tab**, select **+ Add**.
189+
1. Under the **OAuth 2.0** tab, select **+ Add**.
178190

179191
:::image type="content" source="media/api-management-howto-oauth2/oauth-01.png" alt-text="OAuth 2.0 menu":::
180192

@@ -191,27 +203,27 @@ Optionally:
191203

192204
1. The next section of the form contains the **Authorization grant types**, **Authorization endpoint URL**, and **Authorization request method** settings.
193205

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)
195207

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.
197209

198210
Using the v2 endpoint is recommended; however, API Management supports both v1 and v2 endpoints.
199211

200-
`https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize` (v2)
212+
`https://login.microsoftonline.com/{aad-tenant}/oauth2/v2.0/authorize` (v2)
201213

202-
`https://login.microsoftonline.com/<tenant_id>/oauth2/authorize` (v1)
214+
`https://login.microsoftonline.com/{aad-tenant}/oauth2/authorize` (v1)
203215

204216
* The **Authorization request method** specifies how the authorization request is sent to the OAuth 2.0 server. Select **POST**.
205217

206218
:::image type="content" source="media/api-management-howto-oauth2/oauth-03.png" alt-text="Specify authorization settings":::
207219

208-
1. Specify **Token endpoint URL**, **Client authentication methods**, **Access token sending method** and **Default scope**.
220+
1. Specify **Token endpoint URL**, **Client authentication methods**, **Access token sending method**, and **Default scope**.
209221

210-
* 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.
211223

212-
`https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token` (v2)
224+
`https://login.microsoftonline.com/{aad-tenant}/oauth2/v2.0/token` (v2)
213225

214-
`https://login.microsoftonline.com/<tenant_id>/oauth2/token` (v1)
226+
`https://login.microsoftonline.com/{aad-tenant}/oauth2/token` (v1)
215227

216228
* If you use **v1** endpoints, add a body parameter:
217229
* Name: **resource**.
@@ -222,29 +234,29 @@ Optionally:
222234

223235
* Accept the default settings for **Client authentication methods** and **Access token sending method**.
224236

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.
226238

227239
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.
228240

229241
In the developer portal, the URI suffix is of the form:
230242

231243
- `/signin-oauth/code/callback/{authServerName}` for authorization code grant flow
232244
- `/signin-oauth/implicit/callback` for implicit grant flow
233-
234-
Copy the appropriate Redirect URI to the **Authentication** page of your client-app registration.
235245

236246
:::image type="content" source="media/api-management-howto-oauth2/oauth-04.png" alt-text="Add client credentials for the OAuth 2.0 service":::
237247

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+
238250
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.
239251

240252
1. Select **Create** to save the API Management OAuth 2.0 authorization server configuration.
241253

242254
1. [Republish](api-management-howto-developer-portal-customize.md#publish) the developer portal.
243255

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.
246258
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.
248260

249261
## Configure an API to use OAuth 2.0 user authorization
250262

@@ -256,25 +268,33 @@ After saving the OAuth 2.0 server configuration, configure APIs to use this conf
256268

257269
:::image type="content" source="./media/api-management-howto-oauth2/oauth-07.png" alt-text="Configure OAuth 2.0 authorization server":::
258270

259-
260271
## Developer portal - test the OAuth 2.0 user authorization
261272

262273
[!INCLUDE [api-management-test-oauth-authorization](../../includes/api-management-test-oauth-authorization.md)]
263274

275+
## 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.
280+
281+
[!INCLUDE [api-management-configure-validate-jwt](../../includes/api-management-configure-validate-jwt.md)]
282+
283+
264284
## Legacy developer portal - test the OAuth 2.0 user authorization
265285

266286
[!INCLUDE [api-management-portal-legacy.md](../../includes/api-management-portal-legacy.md)]
267287

268-
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.
269289

270-
Click **APIs** in the top menu and select **Echo API**.
290+
Select **APIs** in the top menu and select **Echo API**.
271291

272292
![Echo API][api-management-apis-echo-api]
273293

274294
> [!NOTE]
275295
> If you have only one API configured or visible to your account, then clicking APIs takes you directly to the operations for that API.
276296
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.
278298

279299
![Open console][api-management-open-console]
280300

@@ -291,14 +311,6 @@ Once you've signed in, the **Request headers** are populated with an `Authorizat
291311

292312
At this point you can configure the desired values for the remaining parameters, and submit the request.
293313

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.
299-
300-
[!INCLUDE [api-management-configure-validate-jwt](../../includes/api-management-configure-validate-jwt.md)]
301-
302314
## Next steps
303315

304316
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).
13.8 KB
Loading

includes/api-management-configure-validate-jwt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.author: danlep
88

99
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.
1010

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.
1212
* The value of the `claim` is the client ID of the backend-app you registered in Azure AD.
1313

1414

@@ -24,6 +24,6 @@ The following example policy, when added to the `<inbound>` policy section, chec
2424
```
2525

2626
> [!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`.
2828
2929
For information on how to configure policies, see [Set or edit policies](../articles/api-management/set-edit-policies.md).

includes/api-management-test-oauth-authorization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ Once you've configured your OAuth 2.0 authorization server and configured your A
3232
Authorization: Bearer eyJ0eXAiOi[...]3pkCfvEOyA
3333
```
3434

35-
1. Select **Send** to call the API successfully.
35+
1. Configure the desired values for the remaining parameters, and select **Send** to call the API.

0 commit comments

Comments
 (0)