Class AuthenticationStateClaimsSerializer
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
additionalClaimTypesIEnumerable<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
additionalClaimTypesis 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
authenticationStateAuthenticationStateThe authentication state of the user.
additionalClaimTypesIEnumerable<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
authenticationStateoradditionalClaimTypesis null.