Skip to content
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication;

internal sealed class DeserializedAuthenticationStateProvider : AuthenticationStateProvider
{
// Do not change. This must match all versions of the server-side AuthenticationStateSerializer.PersistenceKey.
private const string PersistenceKey = $"__internal__{nameof(AuthenticationState)}";

private static readonly Task<AuthenticationState> _defaultUnauthenticatedTask =
Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));

private readonly Task<AuthenticationState> _authenticationStateTask = _defaultUnauthenticatedTask;
private readonly Task<AuthenticationState> _authenticationStateTask;

[SupplyParameterFromPersistentComponentState]
private AuthenticationStateData? AuthStateData { get; set; }

[UnconditionalSuppressMessage(
"Trimming",
Expand All @@ -26,14 +26,11 @@ internal sealed class DeserializedAuthenticationStateProvider : AuthenticationSt
[DynamicDependency(JsonSerialized, typeof(AuthenticationStateData))]
[DynamicDependency(JsonSerialized, typeof(IList<ClaimData>))]
[DynamicDependency(JsonSerialized, typeof(ClaimData))]
public DeserializedAuthenticationStateProvider(PersistentComponentState state, IOptions<AuthenticationStateDeserializationOptions> options)
public DeserializedAuthenticationStateProvider(IOptions<AuthenticationStateDeserializationOptions> options)
{
if (!state.TryTakeFromJson<AuthenticationStateData?>(PersistenceKey, out var authenticationStateData) || authenticationStateData is null)
{
return;
}

_authenticationStateTask = options.Value.DeserializationCallback(authenticationStateData);
_authenticationStateTask = AuthStateData is not null
? options.Value.DeserializationCallback(AuthStateData)
: _defaultUnauthenticatedTask;
}

public override Task<AuthenticationState> GetAuthenticationStateAsync() => _authenticationStateTask;
Expand Down
Loading