Skip to content

[Blazor] Update AuthenticationStateProvider to use declarative persistent component state #62063

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 14 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 22, 2025

This PR updates the DeserializedAuthenticationStateProvider to use the declarative persistent component state pattern with the [SupplyParameterFromPersistentComponentState] attribute, matching the approach used for antiforgery token handling.

Changes

  1. Added a property with the [SupplyParameterFromPersistentComponentState] attribute to DeserializedAuthenticationStateProvider to receive authentication state data:
[SupplyParameterFromPersistentComponentState]
private AuthenticationStateData? AuthStateData { get; set; }
  1. Updated the constructor to use this property while maintaining backward compatibility with the existing TryTakeFromJson approach to ensure a smooth transition

  2. Maintained the existing persistence key to ensure compatibility with the AuthenticationStateSerializer class which persists the data on the server side

Benefits

  • Cleaner, more declarative code that follows established patterns in the codebase
  • Reduces the need for manual persistent state management
  • Improves consistency with other components like antiforgery that already use this approach

Fixes #60718.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…FromPersistentComponentState

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [Blazor] Update AuthenticationStateProvider to take advantage of Declarative persistent component state [Blazor] Update AuthenticationStateProvider to use declarative persistent component state May 22, 2025
@Copilot Copilot AI requested a review from ilonatommy May 22, 2025 07:52
Copilot finished work on behalf of ilonatommy May 22, 2025 07:52
…sistent state

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 08:09
…onent state properly

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 09:21
…component state

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 09:36
…nent state

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 09:55
…vider interface

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 10:20
…ttern

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 11:39
…ateProvider

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 11:51
…ndant null check

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 12:07
…Provider

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 22, 2025 14:06
…ton in WASM

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 23, 2025 09:30
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy May 23, 2025 11:26
@ilonatommy
Copy link
Member

Same problem as #61992. The property with SupplyParameterFromPersistentComponentState is public but the error claims it's not. It is declared in internal class but other cases of SupplyParameterFromPersistentComponentState usage are also in internal classes and there, the error does not occur. See

public string? ResourceCollectionUrl

or
public AntiforgeryRequestToken? CurrentToken

…naming pattern

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented May 23, 2025

Same problem as #61992. The property with SupplyParameterFromPersistentComponentState is public but the error claims it's not. It is declared in internal cla...

I've renamed the property from AuthStateData to CurrentAuthenticationState in both classes to match the expected naming pattern used by the framework for computing persistence keys. The property name must match what the framework is looking for during serialization and restoration. This change should fix the issue seen in CI where the framework was looking for a property with that specific name. See commit b5092e8.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 4m6vsblobprodcus384.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspnetcore/aspnetcore/.dotnet/dotnet /home/REDACTED/work/aspnetcore/aspnetcore/.dotnet/sdk/10.0.100-preview.4.25216.37/MSBuild.dll /noautoresponse /nologo /nodemode:1 /nodeReuse:false /low:false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of ilonatommy May 23, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Blazor] Update AuthenticationStateProvider to take advantage of Declarative persistent component state
2 participants