You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory/develop/scenario-protected-web-api-verification-scope-app-roles.md
+12-14Lines changed: 12 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ ms.service: active-directory
10
10
ms.subservice: develop
11
11
ms.topic: conceptual
12
12
ms.workload: identity
13
-
ms.date: 07/15/2020
13
+
ms.date: 10/19/2021
14
14
ms.author: jmprieur
15
15
ms.custom: aaddev
16
16
#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
23
23
- Applications on behalf of users who have the right scopes.
24
24
- Daemon apps that have the right application roles.
25
25
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)
31
30
32
31
To protect an ASP.NET or ASP.NET Core web API, you must add the `[Authorize]` attribute to one of the following items:
33
32
@@ -44,8 +43,8 @@ To protect an ASP.NET or ASP.NET Core web API, you must add the `[Authorize]` at
44
43
45
44
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:
46
45
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.
49
48
50
49
## Verify scopes in APIs called on behalf of users
51
50
@@ -231,7 +230,7 @@ public class TodoListController : ApiController
231
230
}
232
231
```
233
232
234
-
Below is a simplified version of `ValidateScopes`:
233
+
Below is a simplified version of `ValidateScopes`:
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)
255
254
256
255
---
257
256
@@ -290,7 +289,6 @@ MyController : ApiController
290
289
291
290
But for this, you'll need to map the Role claim to "roles" in the Startup.cs file:
For a full version of `ValidateAppRole` for ASP.NETCore, 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.NETCore, see [_RolesRequiredHttpContextExtensions.cs_](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/Resource/RolesRequiredHttpContextExtensions.cs) code.
342
340
343
341
---
344
342
@@ -367,7 +365,7 @@ If you are using Microsoft.Identity.Web on ASP.NET core, you'll need to declare
0 commit comments