Skip to content

Commit dcafa1d

Browse files
authored
Merge pull request #175778 from henrymbuguakiarie/msid-refresh-scenario-protected-web-api-verification-scope-app-roles
[msid][refresh]scenario-protected-web-api-verification-scope-app-roles(ADO-1869145)
2 parents 8e8564d + d939e54 commit dcafa1d

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

articles/active-directory/develop/scenario-protected-web-api-verification-scope-app-roles.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.service: active-directory
1010
ms.subservice: develop
1111
ms.topic: conceptual
1212
ms.workload: identity
13-
ms.date: 07/15/2020
13+
ms.date: 10/19/2021
1414
ms.author: jmprieur
1515
ms.custom: aaddev
1616
#Customer intent: As an application developer, I want to learn how to write a protected web API using the Microsoft identity platform for developers.
@@ -23,11 +23,10 @@ This article describes how you can add authorization to your web API. This prote
2323
- Applications on behalf of users who have the right scopes.
2424
- Daemon apps that have the right application roles.
2525

26-
> [!NOTE]
27-
> The code snippets in this article are extracted from the following code samples on GitHub:
28-
>
29-
> - [ASP.NET Core web API incremental tutorial](https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/blob/master/1.%20Desktop%20app%20calls%20Web%20API/TodoListService/Controllers/TodoListController.cs)
30-
> - [ASP.NET web API sample](https://github.com/Azure-Samples/ms-identity-aspnet-webapi-onbehalfof/blob/master/TodoListService/Controllers/TodoListController.cs)
26+
The code snippets in this article are extracted from the following code samples on GitHub:
27+
28+
- [ASP.NET Core web API incremental tutorial](https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/blob/master/1.%20Desktop%20app%20calls%20Web%20API/TodoListService/Controllers/TodoListController.cs)
29+
- [ASP.NET web API sample](https://github.com/Azure-Samples/ms-identity-aspnet-webapi-onbehalfof/blob/master/TodoListService/Controllers/TodoListController.cs)
3130

3231
To protect an ASP.NET or ASP.NET Core web API, you must add the `[Authorize]` attribute to one of the following items:
3332

@@ -44,8 +43,8 @@ To protect an ASP.NET or ASP.NET Core web API, you must add the `[Authorize]` at
4443

4544
But this protection isn't enough. It guarantees only that ASP.NET and ASP.NET Core validate the token. Your API needs to verify that the token used to call the API is requested with the expected claims. These claims in particular need verification:
4645

47-
- The *scopes* if the API is called on behalf of a user.
48-
- The *app roles* if the API can be called from a daemon app.
46+
- The _scopes_ if the API is called on behalf of a user.
47+
- The _app roles_ if the API can be called from a daemon app.
4948

5049
## Verify scopes in APIs called on behalf of users
5150

@@ -231,7 +230,7 @@ public class TodoListController : ApiController
231230
}
232231
```
233232

234-
Below is a simplified version of `ValidateScopes`:
233+
Below is a simplified version of `ValidateScopes`:
235234

236235
```csharp
237236
private void ValidateScopes(IEnumerable<string> acceptedScopes)
@@ -251,7 +250,7 @@ private void ValidateScopes(IEnumerable<string> acceptedScopes)
251250
}
252251
```
253252

254-
For a full version of `ValidateScopes` for ASP.NET Core, [*ScopesRequiredHttpContextExtensions.cs*](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/Resource/ScopesRequiredHttpContextExtensions.cs)
253+
For a full version of `ValidateScopes` for ASP.NET Core, [_ScopesRequiredHttpContextExtensions.cs_](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/Resource/ScopesRequiredHttpContextExtensions.cs)
255254

256255
---
257256

@@ -290,7 +289,6 @@ MyController : ApiController
290289

291290
But for this, you'll need to map the Role claim to "roles" in the Startup.cs file:
292291

293-
294292
```CSharp
295293
services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
296294
{
@@ -318,7 +316,7 @@ public class TodoListController : ApiController
318316
}
319317
```
320318

321-
A simplified version of `ValidateAppRole` is:
319+
A simplified version of `ValidateAppRole` is:
322320

323321
```csharp
324322
private void ValidateAppRole(string appRole)
@@ -338,7 +336,7 @@ private void ValidateAppRole(string appRole)
338336
}
339337
```
340338

341-
For a full version of `ValidateAppRole` for ASP.NET Core, see [*RolesRequiredHttpContextExtensions.cs*](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/Resource/RolesRequiredHttpContextExtensions.cs) code.
339+
For a full version of `ValidateAppRole` for ASP.NET Core, see [_RolesRequiredHttpContextExtensions.cs_](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/Resource/RolesRequiredHttpContextExtensions.cs) code.
342340
343341
---
344342

@@ -367,7 +365,7 @@ If you are using Microsoft.Identity.Web on ASP.NET core, you'll need to declare
367365
System.UnauthorizedAccessException: IDW10201: Neither scope or roles claim was found in the bearer token.
368366
```
369367

370-
To avoid this exception, set the `AllowWebApiToBeAuthorizedByACL` configuration property to true, in the appsettings.json or programmatically.
368+
To avoid this exception, set the `AllowWebApiToBeAuthorizedByACL` configuration property to true, in the appsettings.json or programmatically.
371369

372370
```Json
373371
{

0 commit comments

Comments
 (0)