Skip to content

Commit 7792188

Browse files
authored
Role-based authorization overhaul (#36885)
1 parent 325c700 commit 7792188

87 files changed

Lines changed: 1154 additions & 1754 deletions

File tree

Some content is hidden

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

aspnetcore/blazor/security/index.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,15 +1227,15 @@ The <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView> component
12271227

12281228
The <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView> component supports *role-based* or *policy-based* authorization.
12291229

1230-
For role-based authorization, use the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView.Roles> parameter. In the following example, the user must have a role claim for either the `Admin` or `Superuser` roles:
1230+
For role-based authorization, use the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView.Roles?displayProperty=nameWithType> parameter. In the following example, the user must have a role claim for either the `Admin` or `Superuser` roles:
12311231

12321232
```razor
12331233
<AuthorizeView Roles="Admin, Superuser">
12341234
<p>You have an 'Admin' or 'Superuser' role claim.</p>
12351235
</AuthorizeView>
12361236
```
12371237

1238-
To require a user have both `Admin` and `Superuser` role claims, nest <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView> components:
1238+
To require both `Admin` and `Superuser` role claims, nest <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView> components:
12391239

12401240
```razor
12411241
<AuthorizeView Roles="Admin">
@@ -1252,7 +1252,7 @@ The preceding code establishes a `Context` for the inner <xref:Microsoft.AspNetC
12521252

12531253
For more information, including configuration guidance, see <xref:security/authorization/roles>.
12541254

1255-
For policy-based authorization, use the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView.Policy> parameter with a single policy name:
1255+
For policy-based authorization, use the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView.Policy?displayProperty=nameWithType> parameter with a single policy name:
12561256

12571257
```razor
12581258
<AuthorizeView Policy="Over21">
@@ -1284,9 +1284,7 @@ If neither <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView.Rol
12841284
* Authenticated (signed-in) users are authorized.
12851285
* Unauthenticated (signed-out) users are unauthorized.
12861286

1287-
Because .NET string comparisons are case-sensitive, matching role and policy names is also case-sensitive. For example, `Admin` (uppercase `A`) is not treated as the same role as `admin` (lowercase `a`).
1288-
1289-
Pascal case is typically used for role and policy names (for example, `BillingAdministrator`), but the use of Pascal case isn't a strict requirement. Different casing schemes, such as camel case, kebab case, and snake case, are permitted. Using spaces in role and policy names is unusual but permitted by the framework. For example, `billing administrator` is an unusual role or policy name format in .NET apps, but it's a valid role or policy name.
1287+
Role matching is typically case-sensitive because role names are stored and compared using .NET string comparisons. For example, `Admin` (uppercase `A`) isn't treated as the same role as `admin` (lowercase `a`). For more information, see <xref:security/authorization/claims#claim-case-sensitivity>. By contrast, ASP.NET Core policy name lookup is typically case-insensitive, so `RequireAdministratorRole` and `requireadministratorrole` refer to the same policy.
12901288

12911289
### Content displayed during asynchronous authentication
12921290

@@ -1321,7 +1319,7 @@ You can only see this if you're signed in.
13211319
> [!IMPORTANT]
13221320
> Only use [`[Authorize]`](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute) on `@page` components reached via the Blazor router. Authorization is only performed as an aspect of routing and *not* for child components rendered within a page. To authorize the display of specific parts within a page, use <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView> instead.
13231321
1324-
The [`[Authorize]` attribute](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute) also supports role-based or policy-based authorization. For role-based authorization, use the <xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute.Roles> parameter:
1322+
The [`[Authorize]` attribute](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute) also supports role-based or policy-based authorization. For role-based authorization, use the <xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute.Roles?displayProperty=nameWithType> parameter:
13251323

13261324
```razor
13271325
@page "/"

aspnetcore/blazor/security/webassembly/microsoft-entra-id-groups-and-roles-net-5-to-7.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,7 @@ Multiple role tests are supported:
761761
if (User.IsInRole("Admin") && User.IsInRole("Developer"))
762762
```
763763

764-
Because .NET string comparisons are case-sensitive, matching role names is also case-sensitive. For example, `Admin` (uppercase `A`) is not treated as the same role as `admin` (lowercase `a`).
765-
766-
Pascal case is typically used for role names (for example, `BillingAdministrator`), but the use of Pascal case isn't a strict requirement. Different casing schemes, such as camel case, kebab case, and snake case, are permitted. Using spaces in role names is also unusual but permitted. For example, `billing administrator` is an unusual role name format in .NET apps but valid.
764+
Role matching is typically case-sensitive because role names are stored and compared using .NET string comparisons. For example, `Admin` (uppercase `A`) isn't treated as the same role as `admin` (lowercase `a`). For more information, see <xref:security/authorization/claims#claim-case-sensitivity>. By contrast, ASP.NET Core policy name lookup is typically case-insensitive, so `RequireAdministratorRole` and `requireadministratorrole` refer to the same policy.
767765

768766
## Additional resources
769767

aspnetcore/blazor/security/webassembly/microsoft-entra-id-groups-and-roles.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,7 @@ Multiple role tests are supported:
463463
if (User.IsInRole("Admin") && User.IsInRole("Developer"))
464464
```
465465

466-
Because .NET string comparisons are case-sensitive, matching role names is also case-sensitive. For example, `Admin` (uppercase `A`) is not treated as the same role as `admin` (lowercase `a`).
467-
468-
Pascal case is typically used for role names (for example, `BillingAdministrator`), but the use of Pascal case isn't a strict requirement. Different casing schemes, such as camel case, kebab case, and snake case, are permitted. Using spaces in role names is also unusual but permitted. For example, `billing administrator` is an unusual role name format in .NET apps but valid.
466+
Role matching is typically case-sensitive because role names are stored and compared using .NET string comparisons. For example, `Admin` (uppercase `A`) isn't treated as the same role as `admin` (lowercase `a`). For more information, see <xref:security/authorization/claims#claim-case-sensitivity>. By contrast, ASP.NET Core policy name lookup is typically case-insensitive, so `RequireAdministratorRole` and `requireadministratorrole` refer to the same policy.
469467

470468
## Additional resources
471469

aspnetcore/fundamentals/static-files.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ app.MapGet("/files/{fileName}", IResult (string fileName) =>
588588
.RequireAuthorization("AuthenticatedUsers");
589589
```
590590

591-
The following route endpoint example uploads files for authenticated users in the administrator role ("`admin`").
591+
The following route endpoint example uploads files for authenticated users in the administrator role (`admin`).
592592

593593
In the `Program` file:
594594

@@ -655,7 +655,7 @@ app.MapGet("/files/{fileName}", IResult (string fileName) =>
655655
.RequireAuthorization("AuthenticatedUsers");
656656
```
657657

658-
The following code uploads files for authenticated users in the administrator role ("`admin`").
658+
The following code uploads files for authenticated users in the administrator role (`admin`).
659659

660660
In `Startup.ConfigureServices`:
661661

0 commit comments

Comments
 (0)