Skip to content

Commit 257056f

Browse files
Merge pull request #219734 from jmprieur/docs-editor/scenario-protected-web-api-ver-1669693618
Fix https://github.com/MicrosoftDocs/azure-docs/issues/91860
2 parents 56a6995 + ec25b0a commit 257056f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ You can also verify the scopes for the whole controller
153153

154154
##### Verify the scopes on a controller with hardcoded scopes
155155

156-
The following code snippet shows the usage of the `[RequiredScope]` attribute with hardcoded scopes on the controller.
156+
The following code snippet shows the usage of the `[RequiredScope]` attribute with hardcoded scopes on the controller. To use the RequiredScopeAttribute, you'll need to either:
157+
158+
- Use `AddMicrosoftIdentitWebApi` in the Startup.cs, as seen in [Code configuration](scenario-protected-web-api-app-configuration.md)
159+
- or otherwise add the `ScopeAuthorizationRequirement` to the authorization policies as explained in [authorization policies](https://github.com/AzureAD/microsoft-identity-web/wiki/authorization-policies).
157160

158161
```csharp
159162
using Microsoft.Identity.Web
@@ -250,7 +253,6 @@ private void ValidateScopes(IEnumerable<string> acceptedScopes)
250253
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)
251254

252255
---
253-
254256
## Verify app roles in APIs called by daemon apps
255257

256258
If your web API is called by a [daemon app](scenario-daemon-overview.md), that app should require an application permission to your web API. As shown in [Exposing application permissions (app roles)](./scenario-protected-web-api-app-registration.md#expose-application-permissions-app-roles), your API exposes such permissions. One example is the `access_as_application` app role.
@@ -274,7 +276,6 @@ public class TodoListController : ApiController
274276
}
275277
```
276278

277-
278279
Instead, you can use the [Authorize(Roles = "access_as_application")] attributes on the controller or an action (or a razor page).
279280

280281
```CSharp
@@ -327,7 +328,6 @@ private void ValidateAppRole(string appRole)
327328
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.
328329
329330
---
330-
331331
### Verify app roles in APIs called on behalf of users
332332

333333
Users can also use roles claims in user assignment patterns, as shown in [How to add app roles in your application and receive them in the token](howto-add-app-roles-in-azure-ad-apps.md). If the roles are assignable to both, checking roles will let apps sign in as users and users sign in as apps. We recommend that you declare different roles for users and apps to prevent this confusion.
@@ -376,3 +376,4 @@ If you set `AllowWebApiToBeAuthorizedByACL` to true, this is **your responsibili
376376

377377
Move on to the next article in this scenario,
378378
[Move to production](scenario-protected-web-api-production.md).
379+

0 commit comments

Comments
 (0)