From 82bb6b79773634a9329f2aaf7def0c35b027e86c Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:48:12 -0500 Subject: [PATCH 1/3] Add a migration scenario for Blazor --- .../migration/80-to-90/includes/blazor.md | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/aspnetcore/migration/80-to-90/includes/blazor.md b/aspnetcore/migration/80-to-90/includes/blazor.md index af0404f9ffa6..89609f36f5b2 100644 --- a/aspnetcore/migration/80-to-90/includes/blazor.md +++ b/aspnetcore/migration/80-to-90/includes/blazor.md @@ -1 +1,29 @@ -Blazor migration guidance will appear here prior to the release of .NET 9, which is scheduled for November, 2024. +### Adopt simplified authentication state serialization for Blazor Web Apps + +Blazor Web Apps can optionally adopt [simplified authentication state serialization](xref:aspnetcore-9#simplified-authentication-state-serialization-for-blazor-web-apps). + +In the server project: + +* Remove the Persisting Authentication State Provider (`PersistingAuthenticationStateProvider.cs`). + +* Remove the service registration from the `Program` file. Instead, chain a call to on : + + ```diff + - builder.Services.AddScoped(); + + builder.Services.AddRazorComponents() + .AddInteractiveServerComponents() + .AddInteractiveWebAssemblyComponents() + + .AddAuthenticationStateSerialization(); + ``` + +In the client project (`.Client`): + +* Remove the Persistent Authentication State Provider (`PersistentAuthenticationStateProvider.cs`). + +* Remove the service registration from the `Program` file. Instead, call on the service collection: + + ```diff + - builder.Services.AddSingleton(); + + builder.Services.AddAuthenticationStateDeserialization(); + ``` From f35e7670dda2b2dd6572985631ab2ac1f88be0a8 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:55:50 -0500 Subject: [PATCH 2/3] Updates --- aspnetcore/migration/80-to-90/includes/blazor.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aspnetcore/migration/80-to-90/includes/blazor.md b/aspnetcore/migration/80-to-90/includes/blazor.md index 89609f36f5b2..f400714b1c7f 100644 --- a/aspnetcore/migration/80-to-90/includes/blazor.md +++ b/aspnetcore/migration/80-to-90/includes/blazor.md @@ -17,6 +17,12 @@ In the server project: + .AddAuthenticationStateSerialization(); ``` +The API only serializes the server-side name and role claims for access in the browser. To include all claims, set to `true`: + +```csharp +.AddAuthenticationStateSerialization(options => options.SerializeAllClaims = true); +``` + In the client project (`.Client`): * Remove the Persistent Authentication State Provider (`PersistentAuthenticationStateProvider.cs`). @@ -27,3 +33,4 @@ In the client project (`.Client`): - builder.Services.AddSingleton(); + builder.Services.AddAuthenticationStateDeserialization(); ``` + From 1dd16d1a652139c6c261279cece2af830a2be3f9 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Wed, 6 Nov 2024 09:28:55 -0500 Subject: [PATCH 3/3] Add cross link to WN --- aspnetcore/migration/80-to-90/includes/blazor.md | 1 + 1 file changed, 1 insertion(+) diff --git a/aspnetcore/migration/80-to-90/includes/blazor.md b/aspnetcore/migration/80-to-90/includes/blazor.md index f400714b1c7f..2b91b487fd7d 100644 --- a/aspnetcore/migration/80-to-90/includes/blazor.md +++ b/aspnetcore/migration/80-to-90/includes/blazor.md @@ -34,3 +34,4 @@ In the client project (`.Client`): + builder.Services.AddAuthenticationStateDeserialization(); ``` +For more information, see .