Skip to content

[Blazor] Update AuthenticationStateProvider to take advantage of Declarative persistent component state #61992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented May 19, 2025

AuthenticationState serialization and deserialization uses declarative persistive component state

In order to solve the problem with non-matching keys in server and WASM:

[ComputeKey] inputString: Microsoft.AspNetCore.Components.WebAssembly.Server.AuthenticationStateSerializer.CurrentAuthenticationState, key: FxhcJRjzApOTVwAvYgWa1WBUHPHfWkmCIHP3kZeqZrM=
[Persist] type: Microsoft.AspNetCore.Components.WebAssembly.Server.AuthenticationStateSerializer, propertyType: Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData, key: FxhcJRjzApOTVwAvYgWa1WBUHPHfWkmCIHP3kZeqZrM=, result: Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData

MonoPlatform.ts:234 [ComputeKey] inputString: Microsoft.AspNetCore.Components.WebAssembly.Authentication.DeserializedAuthenticationStateProvider.CurrentAuthenticationState, key: CVLw9+XoagHLvt9DAe/VnpkOSQt34nib18t39RUYuuw=
MonoPlatform.ts:234 [Restore] type: Microsoft.AspNetCore.Components.WebAssembly.Authentication.DeserializedAuthenticationStateProvider, propertyType: Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData, key: CVLw9+XoagHLvt9DAe/VnpkOSQt34nib18t39RUYuuw=, result: 

A cast to same class on registration was needed. To do that, both serializer and deserializer had to inherit from the same class, e.g. AuthenticationStateProvider.

Description of changes

  • AuthenticationStateSerializer inherits now from AuthenticationStateProvider.
  • Added registration of AuthenticationStateSerializer on the server side to save the state.
  • Added registration of DeserializedAuthenticationStateProvider on the client side to restore the state.

Fixes #60718

@ilonatommy ilonatommy added this to the 10.0-preview5 milestone May 19, 2025
@ilonatommy ilonatommy self-assigned this May 19, 2025
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Blazor] Update AuthenticationStateProvider to take advantage of Declarative persistent component state
1 participant