Skip to content

Commit f512a0e

Browse files
authored
Merge pull request #221464 from MicrosoftDocs/main
12/14 OOB Publish at 7:45AM
2 parents 7655459 + a76dbd1 commit f512a0e

File tree

68 files changed

+660
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+660
-213
lines changed

articles/active-directory/develop/includes/web-api/quickstart-aspnet-core.md

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,30 @@ ms.service: active-directory
88
ms.subservice: develop
99
ms.topic: include
1010
ms.workload: identity
11-
ms.date: 01/11/2022
11+
ms.date: 12/09/2022
1212
ms.author: jmprieur
13-
ms.custom: devx-track-csharp, "scenarios:getting-started", "languages:aspnet-core", mode-api
13+
ms.custom: devx-track-csharp, "scenarios:getting-started", "languages:aspnet-core", mode-api, engagement-fy23
1414
#Customer intent: As an application developer, I want to know how to write an ASP.NET Core web API that uses the Microsoft identity platform to authorize API requests from clients.
1515
---
1616

17-
In this quickstart, you download an ASP.NET Core web API code sample and review the way it restricts resource access to authorized accounts only. The sample supports authorization of personal Microsoft accounts and accounts in any Azure Active Directory (Azure AD) organization.
18-
17+
The following quickstart uses a ASP.NET Core web API code sample to demonstrate how to restrict resource access to authorized accounts. The sample supports authorization of personal Microsoft accounts and accounts in any Azure Active Directory (Azure AD) organization.
1918

2019
## Prerequisites
2120

2221
- Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
2322
- [Azure Active Directory tenant](../../quickstart-create-new-tenant.md)
24-
- [.NET Core SDK 3.1+](https://dotnet.microsoft.com/)
25-
- [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) or [Visual Studio Code](https://code.visualstudio.com/)
23+
- [.NET Core SDK 6.0+](https://dotnet.microsoft.com/)
24+
- [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) or [Visual Studio Code](https://code.visualstudio.com/)
2625

2726
## Step 1: Register the application
2827

2928
First, register the web API in your Azure AD tenant and add a scope by following these steps:
3029

3130
1. Sign in to the [Azure portal](https://portal.azure.com/).
32-
1. If you have access to multiple tenants, 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.
31+
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 to register the application.
3332
1. Search for and select **Azure Active Directory**.
3433
1. Under **Manage**, select **App registrations** > **New registration**.
35-
1. For **Name**, enter a name for your application. For example, enter **AspNetCoreWebApi-Quickstart**. Users of your app will see this name, and you can change it later.
34+
1. For **Name**, enter a name for the application. For example, enter **AspNetCoreWebApi-Quickstart**. Users of the app will see this name, and can be changed later.
3635
1. Select **Register**.
3736
1. Under **Manage**, select **Expose an API** > **Add a scope**. For **Application ID URI**, accept the default by selecting **Save and continue**, and then enter the following details:
3837
- **Scope name**: `access_as_user`
@@ -48,33 +47,78 @@ First, register the web API in your Azure AD tenant and add a scope by following
4847

4948
[Download the ASP.NET Core solution](https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/archive/aspnetcore3-1.zip) from GitHub.
5049

51-
[!INCLUDE [active-directory-develop-path-length-tip](../../../../../includes/active-directory-develop-path-length-tip.md)]
52-
50+
> [!Note]
51+
> The code sample currently targets ASP.NET Core 3.1. The sample can be updated to use .NET Core 6.0 and is covered in the following steps: [Update the sample code to ASP.NET Core 6.0](#step-4-update-the-sample-code-to-aspnet-core-60)
52+
This quickstart will be deprecated in the near future and will be updated to use .NET 6.0.
5353

5454
## Step 3: Configure the ASP.NET Core project
5555

56-
In this step, configure the sample code to work with the app registration that you created earlier.
57-
58-
1. Extract the .zip archive into a folder near the root of your drive. For example, extract into *C:\Azure-Samples*.
56+
In this step, the sample code will be configured to work with the app registration that was created earlier.
5957

60-
We recommend extracting the archive into a directory near the root of your drive to avoid errors caused by path length limitations on Windows.
58+
1. Extract the *.zip* file to a local folder that's close to the root of the disk to avoid errors caused by path length limitations on Windows. For example, extract to *C:\Azure-Samples*.
6159

62-
1. Open the solution in the *webapi* folder in your code editor.
63-
1. Open the *appsettings.json* file and modify the following code:
60+
1. Open the solution in the *webapp* folder in your code editor.
61+
1. In *appsettings.json*, replace the values of `ClientId`, and `TenantId`. The value for the application (client) ID and the directory (tenant) ID, can be found in the app's **Overview** page on the Azure portal.
6462

6563
```json
6664
"ClientId": "Enter_the_Application_Id_here",
6765
"TenantId": "Enter_the_Tenant_Info_Here"
6866
```
6967

70-
- Replace `Enter_the_Application_Id_here` with the application (client) ID of the application that you registered in the Azure portal. You can find the application (client) ID on the app's **Overview** page.
68+
- `Enter_the_Application_Id_Here` is the application (client) ID for the registered application.
7169
- Replace `Enter_the_Tenant_Info_Here` with one of the following:
72-
- If your application supports **Accounts in this organizational directory only**, replace this value with the directory (tenant) ID (a GUID) or tenant name (for example, `contoso.onmicrosoft.com`). You can find the directory (tenant) ID on the app's **Overview** page.
73-
- If your application supports **Accounts in any organizational directory**, replace this value with `organizations`.
74-
- If your application supports **All Microsoft account users**, leave this value as `common`.
70+
- If the application supports **Accounts in this organizational directory only**, replace this value with the directory (tenant) ID (a GUID) or tenant name (for example, `contoso.onmicrosoft.com`). The directory (tenant) ID can be found on the app's **Overview** page.
71+
- If the application supports **Accounts in any organizational directory**, replace this value with `organizations`.
72+
- If the application supports **All Microsoft account users**, leave this value as `common`.
7573

7674
For this quickstart, don't change any other values in the *appsettings.json* file.
7775

76+
### Step 4: Update the sample code to ASP.NET Core 6.0
77+
78+
To update this code sample to target ASP.NET Core 6.0, follow these steps:
79+
80+
1. Open webapi.csproj
81+
1. Remove the following line:
82+
83+
```xml
84+
<TargetFramework>netcoreapp3.1</TargetFramework>
85+
```
86+
87+
1. Add the following line in its place:
88+
89+
```xml
90+
<TargetFramework>netcoreapp6.0</TargetFramework>
91+
```
92+
93+
This step will ensure that the sample is targeting .NET 6.0.
94+
95+
### Step 5: Run the sample
96+
97+
1. Open a terminal and change directory to the project folder.
98+
99+
```powershell
100+
cd webapi
101+
```
102+
103+
1. Run the following command to build the solution:
104+
105+
```powershell
106+
dotnet run
107+
```
108+
109+
If the build has been successful, the following output is displayed:
110+
111+
```powershell
112+
Building...
113+
info: Microsoft.Hosting.Lifetime[0]
114+
Now listening on: https://localhost:{port}
115+
info: Microsoft.Hosting.Lifetime[0]
116+
Now listening on: http://localhost:{port}
117+
info: Microsoft.Hosting.Lifetime[0]
118+
Application started. Press Ctrl+C to shut down.
119+
...
120+
```
121+
78122
## How the sample works
79123

80124
The web API receives a token from a client application, and the code in the web API validates the token. This scenario is explained in more detail in [Scenario: Protected web API](../../scenario-protected-web-api-overview.md).
@@ -93,13 +137,13 @@ The *Microsoft.AspNetCore.Authentication* middleware uses a `Startup` class that
93137

94138
The `AddAuthentication()` method configures the service to add JwtBearer-based authentication.
95139

96-
The line that contains `.AddMicrosoftIdentityWebApi` adds the Microsoft identity platform authorization to your web API. It's then configured to validate access tokens issued by the Microsoft identity platform based on the information in the `AzureAD` section of the *appsettings.json* configuration file:
140+
The line that contains `.AddMicrosoftIdentityWebApi` adds the Microsoft identity platform authorization to the web API. It's then configured to validate access tokens issued by the Microsoft identity platform based on the information in the `AzureAD` section of the *appsettings.json* configuration file:
97141

98142
| *appsettings.json* key | Description |
99143
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
100144
| `ClientId` | Application (client) ID of the application registered in the Azure portal. |
101145
| `Instance` | Security token service (STS) endpoint for the user to authenticate. This value is typically `https://login.microsoftonline.com/`, indicating the Azure public cloud. |
102-
| `TenantId` | Name of your tenant or its tenant ID (a GUID), or `common` to sign in users with work or school accounts or Microsoft personal accounts. |
146+
| `TenantId` | Name of the tenant or its tenant ID (a GUID), or `common` to sign in users with work or school accounts or Microsoft personal accounts. |
103147

104148
The `Configure()` method contains two important methods, `app.UseAuthentication()` and `app.UseAuthorization()`, that enable their named functionality:
105149

@@ -116,7 +160,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
116160

117161
### Protecting a controller, a controller's method, or a Razor page
118162

119-
You can protect a controller or controller methods by using the `[Authorize]` attribute. This attribute restricts access to the controller or methods by allowing only authenticated users. An authentication challenge can be started to access the controller if the user isn't authenticated.
163+
A controller or controller methods can be protected by using the `[Authorize]` attribute. This attribute restricts access to the controller or methods by allowing only authenticated users. An authentication challenge can be started to access the controller if the user isn't authenticated.
120164

121165
```csharp
122166
namespace webapi.Controllers
@@ -157,7 +201,7 @@ namespace webapi.Controllers
157201

158202
## Next steps
159203

160-
The GitHub repository that contains this ASP.NET Core web API code sample includes instructions and more code samples that show you how to:
204+
The following GitHub repository contains the ASP.NET Core web API code sample instructions and more samples that show how to achieve the following:
161205

162206
- Add authentication to a new ASP.NET Core web API.
163207
- Call the web API from a desktop application.

articles/active-directory/develop/includes/web-api/quickstart-dotnet-native-aspnet.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ ms.service: active-directory
88
ms.subservice: develop
99
ms.topic: include
1010
ms.workload: identity
11-
ms.date: 01/11/2022
11+
ms.date: 12/09/2022
1212
ms.author: jmprieur
13-
ms.custom: devx-track-csharp, aaddev, identityplatformtop40, "scenarios:getting-started", "languages:ASP.NET", mode-api
13+
ms.custom: devx-track-csharp, aaddev, identityplatformtop40, "scenarios:getting-started", "languages:ASP.NET", mode-api, engagement-fy23
1414
#Customer intent: As an application developer, I want to know how to set up OpenId Connect authentication in a web application that's built by using Node.js with Express.
1515
---
1616

17-
In this quickstart, you download and run a code sample that demonstrates how to protect an ASP.NET web API by restricting access to its resources to authorized accounts only. The sample supports authorization of personal Microsoft accounts and accounts in any Azure Active Directory (Azure AD) organization.
17+
The following quickstart uses quickstart, uses a code sample that demonstrates how to protect an ASP.NET web API by restricting access to its resources to authorized accounts only. The sample supports authorization of personal Microsoft accounts and accounts in any Azure Active Directory (Azure AD) organization.
1818

19-
The article also uses a Windows Presentation Foundation (WPF) app to demonstrate how you can request an access token to access a web API.
19+
The article also uses a Windows Presentation Foundation (WPF) app to demonstrate how to request an access token to access a web API.
2020

2121
## Prerequisites
2222

2323
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
24-
* Visual Studio 2017 or 2019. Download [Visual Studio for free](https://www.visualstudio.com/downloads/).
24+
* Visual Studio 2022. Download [Visual Studio for free](https://www.visualstudio.com/downloads/).
2525

2626
## Clone or download the sample
2727

28-
You can obtain the sample in either of two ways:
28+
The code sample can be obtained in two ways:
2929

3030
* Clone it from your shell or command line:
3131

@@ -127,7 +127,7 @@ Configure your TodoListClient project by adding the Application ID to the *app.c
127127

128128
## Run your projects
129129

130-
Start both projects. If you are using Visual Studio:
130+
Start both projects. For Visual Studio users;
131131

132132
1. Right click on the Visual Studio solution and select **Properties**
133133

articles/active-directory/develop/scenario-desktop-acquire-token-wam.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.service: active-directory
99
ms.subservice: develop
1010
ms.topic: conceptual
1111
ms.workload: identity
12-
ms.date: 06/07/2022
12+
ms.date: 12/14/2022
1313
ms.author: dmwendia
1414
ms.custom: aaddev, devx-track-python
1515
#Customer intent: As an application developer, I want to know how to write a desktop app that calls web APIs by using the Microsoft identity platform.
@@ -21,11 +21,9 @@ MSAL is able to call Web Account Manager, a Windows 10 component that ships with
2121

2222
## Availability
2323

24-
MSAL 4.25+ supports WAM on UWP, .NET Classic, .NET Core 3.1, and .NET 5.
24+
MSAL 4.25+ supports WAM on UWP, and .NET 5.
2525

26-
For .NET Classic and .NET Core 3.1, WAM functionality is fully supported but you have to add a reference to [Microsoft.Identity.Client.Desktop](https://www.nuget.org/packages/Microsoft.Identity.Client.Desktop/) package, alongside MSAL, and instead of `WithBroker()`, call `.WithWindowsBroker()`.
27-
28-
For .NET 5, target `net5.0-windows10.0.17763.0` (or higher) and not just `net5.0`. Your app will still run on older versions of Windows if you add `<SupportedOSPlatformVersion>7</SupportedOSPlatformVersion>` in the csproj. MSAL will use a browser when WAM isn't available.
26+
For .NET 5, target `net5.0-windows10.0.17763.0` (or higher) and not just `net5.0`. Your app will still run on older versions of Windows if you add `<SupportedOSPlatformVersion>7</SupportedOSPlatformVersion>` in the *.csproj* file. MSAL will use a browser when WAM isn't available.
2927

3028
## WAM value proposition
3129

@@ -78,7 +76,7 @@ catch (MsalUiRequiredException) // no change in the pattern
7876
}
7977
```
8078

81-
Call `.WithBroker(true)`. If a broker isn't present (for example, Win8.1, Mac, or Linux), then MSAL will fall back to a browser. Redirect URI rules apply to the browser.
79+
Call `.WithBroker(true)`. If a broker isn't present (for example, Win8.1, Mac, or Linux), then MSAL will fall back to a browser, where redirect URI rules apply.
8280

8381
## Redirect URI
8482

@@ -131,7 +129,7 @@ Applications cannot remove accounts from Windows!
131129
- Removes app-only (not OS-wide) accounts.
132130

133131
>[!NOTE]
134-
> Apps cannot remove OS accounts. Only users can do that. If an OS account is passed into `RemoveAsync`, and then `GetAccounts` is called with `ListWindowsWorkAndSchoolAccounts` enabled - the same OS account will still be returned.
132+
> Ony users can remove OS accounts, whereas apps themselves cannot. If an OS account is passed into `RemoveAsync`, and then `GetAccounts` is called with `ListWindowsWorkAndSchoolAccounts` enabled, the same OS accounts will still be returned.
135133
136134
## Other considerations
137135

0 commit comments

Comments
 (0)