Property ResolvePrincipal

Assembly: redb.Route.Http.Hosting.dll

Identifies the caller of each request on every listener the manager opens. Null (the default)
leaves requests unidentified and the host byte-for-byte what it was.

It runs once per request: after trusted-proxy resolution, so it sees the client's real address
and scheme; after CORS, so a preflight never reaches it; and before any transport sees the
request. A non-null result is kept in HttpContext.Items under
, and the HTTP, gRPC, SOAP, AS2, WebSocket and
SignalR consumers put it on the exchange (ExchangePrincipal).


It identifies; it does not authorize. Return null for an anonymous caller: such a request
is still served, because one listener carries routes with different requirements, and whether
an anonymous caller is acceptable is each route's decision. A resolver that throws fails the
request with 500 and an error log instead — one that could not decide must not quietly hand the
route an anonymous caller that may not be one. Build the identity with an authentication type
(new ClaimsIdentity(claims, "Bearer")): code that reads the principal treats an identity that
is not authenticated as anonymous.


A transport's own authenticate hook (WsComponent.Authenticate,
SignalRComponent.Authenticate) takes precedence on that transport's paths.

public Func<HttpContext, Task<ClaimsPrincipal?>>? ResolvePrincipal { get; set; }