Blazor WASM secure app via Imports update (#23187)

pull/23198/head
Luke Latham 2021-09-02 06:06:32 -05:00 committed by GitHub
parent bbb2da9b0e
commit 1203e32c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 3 deletions

View File

@ -68,12 +68,23 @@ In Blazor WebAssembly apps, authorization checks can be bypassed because all cli
Apply the [`[Authorize]` attribute](xref:blazor/security/index#authorize-attribute) ([API documentation](xref:System.Web.Mvc.AuthorizeAttribute)) to each Razor component of the app using one of the following approaches:
* Use the [`@attribute`](xref:mvc/views/razor#attribute) directive in the `_Imports.razor` file:
* In the app's Imports file, add an [`@using`](xref:mvc/views/razor#using) directive for the <xref:Microsoft.AspNetCore.Authorization?displayProperty=fullName> namespace with an [`@attribute`](xref:mvc/views/razor#attribute) directive for the [`[Authorize]` attribute](xref:blazor/security/index#authorize-attribute).
`_Imports.razor`:
```razor
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
```
Allow anonymous access to the `Authentication` component to permit redirection to the Idenfity Provider. Add the following Razor code to the `Authentication` component under its [`@page`](xref:mvc/views/razor#page) directive.
`Pages/Authentication.razor`:
```razor
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@attribute [AllowAnonymous]
```
* Add the attribute to each Razor component in the `Pages` folder.
@ -190,12 +201,23 @@ In Blazor WebAssembly apps, authorization checks can be bypassed because all cli
Apply the [`[Authorize]` attribute](xref:blazor/security/index#authorize-attribute) ([API documentation](xref:System.Web.Mvc.AuthorizeAttribute)) to each Razor component of the app using one of the following approaches:
* Use the [`@attribute`](xref:mvc/views/razor#attribute) directive in the `_Imports.razor` file:
* In the app's Imports file, add an [`@using`](xref:mvc/views/razor#using) directive for the <xref:Microsoft.AspNetCore.Authorization?displayProperty=fullName> namespace with an [`@attribute`](xref:mvc/views/razor#attribute) directive for the [`[Authorize]` attribute](xref:blazor/security/index#authorize-attribute).
`_Imports.razor`:
```razor
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
```
Allow anonymous access to the `Authentication` component to permit redirection to the Idenfity Provider. Add the following Razor code to the `Authentication` component under its [`@page`](xref:mvc/views/razor#page) directive.
`Pages/Authentication.razor`:
```razor
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@attribute [AllowAnonymous]
```
* Add the attribute to each Razor component in the `Pages` folder.
@ -312,12 +334,23 @@ In Blazor WebAssembly apps, authorization checks can be bypassed because all cli
Apply the [`[Authorize]` attribute](xref:blazor/security/index#authorize-attribute) ([API documentation](xref:System.Web.Mvc.AuthorizeAttribute)) to each Razor component of the app using one of the following approaches:
* Use the [`@attribute`](xref:mvc/views/razor#attribute) directive in the `_Imports.razor` file:
* In the app's Imports file, add an [`@using`](xref:mvc/views/razor#using) directive for the <xref:Microsoft.AspNetCore.Authorization?displayProperty=fullName> namespace with an [`@attribute`](xref:mvc/views/razor#attribute) directive for the [`[Authorize]` attribute](xref:blazor/security/index#authorize-attribute).
`_Imports.razor`:
```razor
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
```
Allow anonymous access to the `Authentication` component to permit redirection to the Idenfity Provider. Add the following Razor code to the `Authentication` component under its [`@page`](xref:mvc/views/razor#page) directive.
`Pages/Authentication.razor`:
```razor
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@attribute [AllowAnonymous]
```
* Add the attribute to each Razor component in the `Pages` folder.