Skip to content

Commit 8cb36c8

Browse files
authored
Fix auth state as a cascading param guidance (dotnet#17000)
1 parent f275a6f commit 8cb36c8

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

aspnetcore/security/blazor/index.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn about Blazor authentication and authorization scenarios.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 02/02/2020
8+
ms.date: 02/13/2020
99
no-loc: [Blazor, SignalR]
1010
uid: security/blazor/index
1111
---
@@ -131,7 +131,7 @@ The `AuthenticationStateProvider` service can provide the current user's <xref:S
131131
@using Microsoft.AspNetCore.Components.Authorization
132132
@inject AuthenticationStateProvider AuthenticationStateProvider
133133
134-
<button @onclick="@LogUsername">Write user info to console</button>
134+
<button @onclick="LogUsername">Write user info to console</button>
135135
136136
@code {
137137
private async Task LogUsername()
@@ -214,7 +214,7 @@ If authentication state data is required for procedural logic, such as when perf
214214
```razor
215215
@page "/"
216216
217-
<button @onclick="@LogUsername">Log username</button>
217+
<button @onclick="LogUsername">Log username</button>
218218
219219
@code {
220220
[CascadingParameter]
@@ -245,6 +245,8 @@ If `user.Identity.IsAuthenticated` is `true`, claims can be enumerated and membe
245245
Set up the `Task<AuthenticationState>` cascading parameter using the `AuthorizeRouteView` and `CascadingAuthenticationState` components in the *App.razor* file:
246246

247247
```razor
248+
@using Microsoft.AspNetCore.Components.Authorization
249+
248250
<Router AppAssembly="@typeof(Program).Assembly">
249251
<Found Context="routeData">
250252
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
@@ -259,6 +261,13 @@ Set up the `Task<AuthenticationState>` cascading parameter using the `AuthorizeR
259261
</Router>
260262
```
261263

264+
Add services for options and authorization to `Program.Main`:
265+
266+
```csharp
267+
builder.Services.AddOptions();
268+
builder.Services.AddAuthorizationCore();
269+
```
270+
262271
## Authorization
263272

264273
After a user is authenticated, *authorization* rules are applied to control what the user can do.

0 commit comments

Comments
 (0)