Namespace Arc4u.Blazor
Classes
- AppPrincipalFromAuthenticationState
Rebuilds the AppPrincipal from the authentication state serialized by the Blazor server, and sets it in the IApplicationContext.
- AppPrincipalServerAuthenticationStateProvider
Server (Interactive Server / SignalR circuit) counterpart of the WebAssembly
Arc4u.Blazor.AppPrincipalFromAuthenticationStateused on the client.On the client, the AppPrincipal is rebuilt from the serialized authentication state through the
DeserializationCallbackand pushed into the circuit-scoped IApplicationContext.On the server,
AppPrincipalTransform(anIClaimsTransformation) runs in the HTTP request scope duringUseAuthentication(), so the IApplicationContext it populates belongs to that request scope and is discarded before the interactive circuit runs. The circuit uses its own DI scope, whose IApplicationContext is therefore empty.This provider closes that gap: it derives from Microsoft.AspNetCore.Components.Server.ServerAuthenticationStateProvider (which the Blazor endpoint seeds from
HttpContext.User) and, whenever the authentication state is resolved inside the circuit, rebuilds the AppPrincipal and sets it on the circuit-scoped IApplicationContext — mirroring the client behaviour.When the state changes (for example when the circuit reconnects with another user or without a user), Blazor forwards the new state without calling GetAuthenticationStateAsync() again, so the provider also updates the IApplicationContext on AuthenticationStateChanged.
- ApplicationContextCircuitHandler
Populates the circuit-scoped IApplicationContext for Interactive Server components.
An Interactive Server component runs in a SignalR circuit that owns its own DI scope, distinct from the HTTP request scope where
AppPrincipalTransform(and, during prerendering, AppPrincipalServerAuthenticationStateProvider) populate the request-scoped IApplicationContext. That request scope is disposed once the response is sent, so the circuit starts with an empty IApplicationContext and component event handlers (e.g. a button click on the Counter page) see a nullPrincipal.This handler resolves the circuit-scoped AuthenticationStateProvider once the SignalR connection is up and builds the AppPrincipal into the circuit-scoped IApplicationContext, so it is available for the whole lifetime of the circuit — independent of whether/when the render pipeline re-invokes
GetAuthenticationStateAsync.It also follows the changes of the circuit's authentication state: when the circuit reconnects, Blazor sets the user of the new connection after the OnConnectionUpAsync(Circuit, CancellationToken) handlers ran, and a revalidating provider can turn the state anonymous. Nothing reads the state again after such a change, so the handler rebuilds the principal from the new state, or clears it for an anonymous user.
- BlazorController
This controller is used to obtain an access token as a result of a back-end authentication and transmit it back to the Blazor application.
- SetCultureUIExtensions
Provides extension methods for setting the default culture.
- WindowInterop
Provides a mechanism to interact with an OAuth token window.
Interfaces
- IAppPrincipalAuthenticationStateProvider
Builds an authentication state whose user is an AppPrincipal from serialized authentication data.
- ITokenWindowInterop
Defines a contract for interacting with an OAuth token window.