Property Authenticate

Assembly: redb.Route.WebSocket.dll

Authenticates a WebSocket handshake. Returns the principal to attach to the request (its
NameIdentifier claim reaches the route as the redbWs.UserId header), or null
to reject the upgrade with 401.

Browsers cannot set headers on a WebSocket handshake, so a token normally arrives in the
access_token query parameter: read it from there and from the Authorization header.


The principal is also put on every exchange the socket produces (ExchangePrincipal). Build its
identity with an authentication type (new ClaimsIdentity(claims, "Bearer")): code that reads
the principal treats an identity that is not authenticated as anonymous.

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