Skip to content

Commit 61cd2b4

Browse files
authored
Merge pull request #232360 from henrymbuguakiarie/msid-gtd-combine-howto-set
[msid][gtd][staging-release] Combining tutorial sets for web app, web API and SPA (ADO-80411)
2 parents 2c8ab50 + 6384c8b commit 61cd2b4

12 files changed

+988
-0
lines changed

articles/active-directory/develop/TOC.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
href: single-page-app-tutorial-03-sign-in-users.md
5757
- name: 4 - Get user data from web API
5858
href: single-page-app-tutorial-04-call-api.md
59+
- name: Web API
60+
items:
61+
- name: 1 - Register the API
62+
href: web-api-tutorial-01-register-app.md
63+
- name: 2 - Create and configure project
64+
href: web-api-tutorial-02-prepare-api.md
65+
- name: 3 - Protect API endpoint
66+
href: web-api-tutorial-03-protect-endpoint.md
5967
- name: Web app
6068
items:
6169
- name: ASP.NET
@@ -450,6 +458,10 @@
450458
href: sample-v2-code.md#web-api
451459
- name: How-to
452460
items:
461+
- name: Call an ASP.NET API with cURL
462+
href: howto-call-a-web-api-with-curl.md
463+
- name: Call an ASP.NET API with Postman
464+
href: howto-call-a-web-api-with-postman.md
453465
- name: Protected web API
454466
items:
455467
- name: Overview

articles/active-directory/develop/howto-call-a-web-api-with-curl.md

Lines changed: 320 additions & 0 deletions
Large diffs are not rendered by default.

articles/active-directory/develop/howto-call-a-web-api-with-postman.md

Lines changed: 303 additions & 0 deletions
Large diffs are not rendered by default.
181 KB
Loading
181 KB
Loading
86.9 KB
Loading
82.1 KB
Loading
30.2 KB
Loading
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: "Tutorial: Register a web API with the Microsoft identity platform"
3+
description: In this tutorial, you learn how to register a web API with the Microsoft identity platform.
4+
author: cilwerner
5+
ms.author: cwerner
6+
manager: CelesteDG
7+
ms.service: active-directory
8+
ms.topic: tutorial
9+
ms.date: 11/1/2022
10+
#Customer intent: As an application developer, I want to know how to register my application with the Microsoft identity platform so that the security token service can issue access tokens to client applications that request them.
11+
---
12+
13+
# Tutorial: Register a web API with the Microsoft identity platform
14+
15+
To interact with the Microsoft identity platform, Azure Active Directory (Azure AD) must be made aware of the application you create. This tutorial shows you how to register an application in a tenant on the Azure portal.
16+
17+
In this tutorial:
18+
19+
> [!div class="checklist"]
20+
> * Register a web API in a tenant
21+
> * Record the web API's unique identifiers
22+
> * Expose an API by adding a scope
23+
24+
## Prerequisites
25+
26+
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/).
27+
* This Azure account must have permissions to manage applications. Use any of the following roles needed to register the application:
28+
* Application administrator
29+
* Application developer
30+
* Cloud application administrator
31+
32+
## Register the application and record identifiers
33+
34+
To complete registration, provide the application a name and specify the supported account types. Once registered, the application **Overview** page will display the identifiers needed in the application source code.
35+
36+
1. Sign in to the [Azure portal](https://portal.azure.com/).
37+
1. If access to multiple tenants is available, use the **Directories + subscriptions** filter :::image type="icon" source="media/common/portal-directory-subscription-filter.png" border="false"::: in the top menu to switch to the tenant in which you want to register the application.
38+
1. Search for and select **Azure Active Directory**.
39+
1. Under **Manage**, select **App registrations > New registration**.
40+
1. Enter a **Name** for the application, such as *NewWebAPI1*.
41+
1. For **Supported account types**, select **Accounts in this organizational directory only**. For information on different account types, select **Help me choose** option.
42+
1. Select **Register**.
43+
44+
:::image type="content" source="./media/web-api-tutorial-01-register-app/register-application.png" alt-text="Screenshot that shows how to enter a name and select the account type.":::
45+
46+
1. The application's **Overview** pane is displayed when registration is complete. Record the **Directory (tenant) ID** and the **Application (client) ID** to be used in your application source code.
47+
48+
:::image type="content" source="./media/web-api-tutorial-01-register-app/record-identifiers.png" alt-text="Screenshot that shows the identifier values on the overview page.":::
49+
50+
>[!NOTE]
51+
> The **Supported account types** can be changed by referring to [Modify the accounts supported by an application](howto-modify-supported-accounts.md).
52+
53+
## Expose an API
54+
55+
Once the API is registered, you can configure its permission by defining the scopes that the API exposes to client applications. Client applications request permission to perform operations by passing an access token along with its requests to the protected web API. The web API then performs the requested operation only if the access token it receives contains the required scopes.
56+
57+
1. Under **Manage**, select **Expose an API > Add a scope**. Accept the proposed **Application ID URI** `(api://{clientId})` by selecting **Save and continue**. The `{clientId}` will be the value recorded from the **Overview** page. Then enter the following information:
58+
1. For **Scope name**, enter `Forecast.Read`.
59+
1. For **Who can consent**, ensure that the **Admins and users** option is selected.
60+
1. In the **Admin consent display name** box, enter `Read forecast data`.
61+
1. In the **Admin consent description** box, enter `Allows the application to read weather forecast data`.
62+
1. In the **User consent display name** box, enter `Read forecast data`.
63+
1. In the **User consent description** box, enter `Allows the application to read weather forecast data`.
64+
1. Ensure that the **State** is set to **Enabled**.
65+
1. Select **Add scope**. If the scope has been entered correctly, it'll be listed in the **Expose an API** pane.
66+
67+
:::image type="content" source="./media/web-api-tutorial-01-register-app/add-a-scope-inline.png" alt-text="Screenshot that shows the field values when adding the scope to an API." lightbox="./media/web-api-tutorial-01-register-app/add-a-scope-expanded.png":::
68+
69+
## Next steps
70+
71+
> [!div class="nextstepaction"]
72+
> [Tutorial: Create an ASP.NET Core project and configure the API](web-api-tutorial-02-prepare-api.md)
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: "Tutorial: Create and configure an ASP.NET Core project for authentication"
3+
description: "Create and configure the API in an IDE, add configuration for authentication and install required packages"
4+
author: cilwerner
5+
ms.author: cwerner
6+
manager: CelesteDG
7+
ms.service: active-directory
8+
ms.topic: tutorial
9+
ms.date: 11/1/2022
10+
#Customer intent: As an application developer, I want to create an ASP.NET Core project in an IDE, then configure it in such a way that I can add authentication with Azure AD.
11+
---
12+
13+
# Tutorial: Create and configure an ASP.NET Core project for authentication
14+
15+
After registration is complete, a ASP.NET Core project can be created using an integrated development environment (IDE). This tutorial demonstrates how to create an ASP.NET Core project using an IDE and configure for authentication and authorization.
16+
17+
In this tutorial:
18+
19+
> [!div class="checklist"]
20+
> * Create an **ASP.NET Core Empty**
21+
> * Configure the settings for the application
22+
> * Identify and install the required NuGet packages
23+
24+
## Prerequisites
25+
26+
* Completion of the prerequisites and steps in [Tutorial: Register web API with the Microsoft identity platform](web-api-tutorial-01-register-app.md).
27+
* You can download the IDEs used in this tutorial from the [Downloads](https://visualstudio.microsoft.com/downloads) page.
28+
- Visual Studio 2022
29+
- Visual Studio Code
30+
- Visual Studio 2022 for Mac
31+
- A minimum requirement of [.NET Core 6.0 SDK](https://dotnet.microsoft.com/download/dotnet).
32+
33+
## Create an ASP.NET Core project
34+
35+
Use the following tabs to create an ASP.NET Core project within an IDE.
36+
37+
### [Visual Studio](#tab/visual-studio)
38+
39+
1. Open Visual Studio, and then select **Create a new project**.
40+
1. Search for and choose the **ASP.NET Core Empty** template, and then select **Next**.
41+
1. Enter a name for the project, such as *NewWebAPILocal*.
42+
1. Choose a location for the project or accept the default option, and then select **Next**.
43+
1. Accept the default for the **Framework** and **Configure for HTTPS**.
44+
1. Select **Create**.
45+
46+
### [Visual Studio Code](#tab/visual-studio-code)
47+
48+
1. Open Visual Studio Code, select **File > Open Folder...**. Navigate to and select the location in which to create your project.
49+
1. Open up a new terminal by selecting **Terminal** in the top bar, then **New Terminal**.
50+
1. Create a new folder using the **New Folder...** icon in the **Explorer** pane. Provide a name similar to the one registered previously, for example, *NewWebAPILocal*.
51+
1. Open a new terminal by selecting **Terminal > New Terminal**.
52+
1. To create an **ASP.NET Core Empty** template, run the following commands in the terminal to change into the directory and create the project:
53+
54+
```powershell
55+
cd NewWebAPILocal
56+
dotnet new web
57+
```
58+
59+
### [Visual Studio for Mac](#tab/visual-studio-for-mac)
60+
61+
1. Open Visual Studio, and then select **New**.
62+
1. Under **Web and Console** in the left navigation bar, select **App**.
63+
1. Under **ASP.NET Core**, select **API** and ensure **C#** is selected in the drop down menu, then select **Continue**.
64+
1. Accept the default for the **Target Framework** and **Advanced**, then select **Continue**.
65+
1. Enter a name for the **Project name**, this will be reflected in **Solution Name**. Provide a similar name to the one registered on the Azure portal, such as *NewAPI1*.
66+
1. Accept the default location for the project or choose a different location, and then select **Create**.
67+
---
68+
69+
## Configure the ASP.NET Core project
70+
71+
The values recorded earlier will be used in *appsettings.json* to configure the application for authentication. *appsettings.json* is a configuration file that is used to store application settings used during run-time.
72+
73+
1. Open *appsettings.json* and replace the file contents with the following code snippet:
74+
75+
```json
76+
{
77+
"AzureAd": {
78+
"Instance": "https://login.microsoftonline.com/",
79+
"ClientId": "Enter the client ID here",
80+
"TenantId": "Enter the tenant ID here",
81+
"Scopes": "Forecast.Read"
82+
},
83+
"Logging": {
84+
"LogLevel": {
85+
"Default": "Information",
86+
"Microsoft.AspNetCore": "Warning"
87+
}
88+
},
89+
"AllowedHosts": "*"
90+
}
91+
```
92+
93+
* `Instance` - The endpoint of the cloud provider. Check with the different available endpoints in [National clouds](authentication-national-cloud.md#azure-ad-authentication-endpoints).
94+
* `TenantId` - The identifier of the tenant where the application is registered. Replace the text in quotes with the **Directory (tenant) ID** value that was recorded earlier from the overview page of the registered application.
95+
* `ClientId` - The identifier of the application, also referred to as the client. Replace the text in quotes with the **Application (client) ID** value that was recorded earlier from the overview page of the registered application.
96+
* `Scopes` - The scope that is used to request access to the application. For this tutorial, the scope is `Forecast.Read`.
97+
1. Save the changes to the file.
98+
99+
## Install identity packages
100+
101+
Identity related **NuGet packages** must be installed in the project for authentication of users to be enabled.
102+
103+
### [Visual Studio](#tab/visual-studio)
104+
105+
1. In the top menu, select **Tools** > **NuGet Package Manager** > **Manage NuGet Packages for Solution**.
106+
1. With the **Browse** tab selected, search for **Microsoft.Identity.Web**, select the `Microsoft.Identity.Web` package, select the **Project** checkbox, and then select **Install**.
107+
1. Select **Ok** or **I Accept** for other windows that may appear.
108+
109+
### [Visual Studio Code](#tab/visual-studio-code)
110+
111+
1. In the terminal opened in the previous section, enter the following command:
112+
113+
```powershell
114+
dotnet add package Microsoft.Identity.Web
115+
```
116+
117+
### [Visual Studio for Mac](#tab/visual-studio-for-mac)
118+
119+
1. In the top menu, select **Tools** > **Manage NuGet Packages**.
120+
1. Search for **Microsoft.Identity.Web**, select the `Microsoft.Identity.Web` package, select **Project**, and then select **Add Package**.
121+
1. Modify the search to **Microsoft.Identity.Web.UI** and select **Add Packages**.
122+
1. In the pop-up, ensure the correct project is selected, then select **Ok**.
123+
1. Select **Accept** if other **License Acceptance** windows appear.
124+
125+
---
126+
127+
## Next steps
128+
129+
> [!div class="nextstepaction"]
130+
> [Tutorial: Implement a protected endpoint to your API](web-api-tutorial-03-protect-endpoint.md)

0 commit comments

Comments
 (0)