Table of Contents

Class AuthenticationStateClaimsSerializer

Namespace
Arc4u.Blazor
Assembly
Arc4u.OAuth2.AspNetCore.Blazor.dll

Writes the signed-in user's authentication state into the page for the WebAssembly client with only the claims the client needs: the name claim, the role claims, and the claim types the application lists. It replaces SerializeAllClaims = true, which sends every claim of the user to the browser.

public static class AuthenticationStateClaimsSerializer
Inheritance
AuthenticationStateClaimsSerializer
Inherited Members

Remarks

Plug it into the serialization of the server project: .AddAuthenticationStateSerialization(o => o.SerializationCallback = AuthenticationStateClaimsSerializer.Create(ClaimTypes.Email)).

The SessionKey claim (the key of the user's session in the cookie's session store) is never sent, even when it is listed. Send Authorization only when the WebAssembly client evaluates authorizations itself: the server is where they are enforced.

Methods

Create(params IEnumerable<string>)

Creates a serialization callback that sends the name and role claims plus the claims of additionalClaimTypes.

public static Func<AuthenticationState, ValueTask<AuthenticationStateData?>> Create(params IEnumerable<string> additionalClaimTypes)

Parameters

additionalClaimTypes IEnumerable<string>

The claim types sent besides the name and role claims.

Returns

Func<AuthenticationState, ValueTask<AuthenticationStateData>>

The callback to set as AuthenticationStateSerializationOptions.SerializationCallback.

Exceptions

ArgumentNullException

additionalClaimTypes is null.

SerializeAsync(AuthenticationState, IEnumerable<string>)

Builds the authentication state data: nothing for an anonymous user; otherwise the first identity's name and role claim types, the first name claim, every role claim, and every claim whose type is in additionalClaimTypes, except the claims that never leave the server.

public static ValueTask<AuthenticationStateData?> SerializeAsync(AuthenticationState authenticationState, IEnumerable<string> additionalClaimTypes)

Parameters

authenticationState AuthenticationState

The authentication state of the user.

additionalClaimTypes IEnumerable<string>

The claim types sent besides the name and role claims.

Returns

ValueTask<AuthenticationStateData>

The data written into the page, or null for an anonymous user.

Exceptions

ArgumentNullException

authenticationState or additionalClaimTypes is null.