Skip to content

Commit ae02f26

Browse files
committed
Update web quickstarts to Id.Web2
1 parent 18db93b commit ae02f26

File tree

2 files changed

+7
-56
lines changed

2 files changed

+7
-56
lines changed

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

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: active-directory
88
ms.subservice: develop
99
ms.topic: include
1010
ms.workload: identity
11-
ms.date: 12/09/2022
11+
ms.date: 04/16/2023
1212
ms.author: cwerner
1313
ms.reviewer: jmprieur
1414
ms.custom: devx-track-csharp, "scenarios:getting-started", "languages:aspnet-core", mode-api, engagement-fy23
@@ -48,10 +48,6 @@ First, register the web API in your Azure AD tenant and add a scope by following
4848

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

51-
> [!Note]
52-
> 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)
53-
This quickstart will be deprecated in the near future and will be updated to use .NET 6.0.
54-
5551
## Step 3: Configure the ASP.NET Core project
5652

5753
In this step, the sample code will be configured to work with the app registration that was created earlier.
@@ -74,26 +70,7 @@ In this step, the sample code will be configured to work with the app registrati
7470

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

77-
### Step 4: Update the sample code to ASP.NET Core 6.0
78-
79-
To update this code sample to target ASP.NET Core 6.0, follow these steps:
80-
81-
1. Open webapi.csproj
82-
1. Remove the following line:
83-
84-
```xml
85-
<TargetFramework>netcoreapp3.1</TargetFramework>
86-
```
87-
88-
1. Add the following line in its place:
89-
90-
```xml
91-
<TargetFramework>netcoreapp6.0</TargetFramework>
92-
```
93-
94-
This step will ensure that the sample is targeting the .NET Core 6.0 framework.
95-
96-
### Step 5: Run the sample
73+
### Step 4: Run the sample
9774

9875
1. Open a terminal and change directory to the project folder.
9976

@@ -167,31 +144,28 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
167144
namespace webapi.Controllers
168145
{
169146
[Authorize]
147+
[RequiredScope("access_as_user")]
170148
[ApiController]
171149
[Route("[controller]")]
172150
public class WeatherForecastController : ControllerBase
173151
```
174152

175153
### Validation of scope in the controller
176154

177-
The code in the API verifies that the required scopes are in the token by using `HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);`:
155+
The code in the API verifies that the required scopes are in the token by using `[RequiredScope("access_as_user")]` attribute:
178156

179157
```csharp
180158
namespace webapi.Controllers
181159
{
182160
[Authorize]
161+
[RequiredScope("access_as_user")]
183162
[ApiController]
184163
[Route("[controller]")]
185164
public class WeatherForecastController : ControllerBase
186165
{
187-
// The web API will only accept tokens 1) for users, and 2) having the "access_as_user" scope for this API
188-
static readonly string[] scopeRequiredByApi = new string[] { "access_as_user" };
189-
190166
[HttpGet]
191167
public IEnumerable<WeatherForecast> Get()
192168
{
193-
HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);
194-
195169
// some code here
196170
}
197171
}

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.subservice: develop
1010
ms.topic: quickstart
1111
ms.workload: identity
1212

13-
ms.date: 12/19/2022
13+
ms.date: 04/16/2023
1414
ms.author: cwerner
1515

1616
ms.reviewer: jmprieur
@@ -50,10 +50,6 @@ See [How the sample works](#how-the-sample-works) for an illustration.
5050

5151
[Download the ASP.NET Core solution](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/archive/aspnetcore3-1-callsgraph.zip)
5252

53-
> [!Note]
54-
> 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)
55-
This quickstart will be deprecated in the near future and will be updated to use .NET 6.0.
56-
5753
### Step 3: Configure your ASP.NET Core project
5854

5955
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*.
@@ -74,27 +70,8 @@ This quickstart will be deprecated in the near future and will be updated to use
7470
- Replace `Enter_the_Client_Secret_Here` with the **Client secret** that was created and recorded in an earlier step.
7571

7672
For this quickstart, don't change any other values in the *appsettings.json* file.
77-
78-
### Step 4: Update the sample code to ASP.NET Core 6.0
79-
80-
To update this code sample to target ASP.NET Core 6.0, follow these steps:
81-
82-
1. Open WebApp-OpenIDConnect-DotNet.csproj
83-
1. Remove the following line:
84-
85-
```xml
86-
<TargetFramework>netcoreapp3.1</TargetFramework>
87-
```
88-
89-
1. Add the following line in its place:
90-
91-
```xml
92-
<TargetFramework>netcoreapp6.0</TargetFramework>
93-
```
94-
95-
This step will ensure that the sample is targeting the .NET Core 6.0 framework.
9673

97-
### Step 5: Build and run the application
74+
### Step 4: Build and run the application
9875

9976
Build and run the app in Visual Studio by selecting the **Debug** menu > **Start Debugging**, or by pressing the F5 key.
10077

0 commit comments

Comments
 (0)