Skip to content

Commit

Permalink
Add a migration scenario for Blazor (#34011)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Nov 6, 2024
1 parent b259981 commit ccb597e
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion aspnetcore/migration/80-to-90/includes/blazor.md
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
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 <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyRazorComponentsBuilderExtensions.AddAuthenticationStateSerialization%2A> on <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A>:

```diff
- builder.Services.AddScoped<AuthenticationStateProvider, PersistingAuthenticationStateProvider>();

builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents()
+ .AddAuthenticationStateSerialization();
```

The API only serializes the server-side name and role claims for access in the browser. To include all claims, set <xref:Microsoft.AspNetCore.Components.WebAssembly.Server.AuthenticationStateSerializationOptions.SerializeAllClaims> to `true`:

```csharp
.AddAuthenticationStateSerialization(options => options.SerializeAllClaims = true);
```

In the client project (`.Client`):

* Remove the Persistent Authentication State Provider (`PersistentAuthenticationStateProvider.cs`).

* Remove the service registration from the `Program` file. Instead, call <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyAuthenticationServiceCollectionExtensions.AddAuthenticationStateDeserialization%2A> on the service collection:

```diff
- builder.Services.AddSingleton<AuthenticationStateProvider, PersistentAuthenticationStateProvider>();
+ builder.Services.AddAuthenticationStateDeserialization();
```

For more information, see <xref:aspnetcore-9#simplified-authentication-state-serialization-for-blazor-web-apps>.

0 comments on commit ccb597e

Please sign in to comment.