I'm developing an ASP.NET Core MVC web application. The application uses Windows Authentication. I want to send notifications to the client side from an API controller once it receives a post request. I found this resource https://learn.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-5.0) that says I need to use a CustomUserIdProvider to get the Id of tat specific user. However, I'm not sure how should I call the following method:
_myHub.Clients.User(specificUserId).SendAsync("ReceiveMessage", message);
How can I get that specificUserId in my API controller. I tried injecting the CustomUserIdProvider and then calling this method:
_myHub.Clients.User(_customUserIdProvider.GetUserId(conn)).SendAsync("ReceiveMessage", message);
However I don't know how do I get the HubConnectionContext conn object that is required by the GetUserId method from this API controller.
This is the CustomUserIdProvider class:
public class CustomUserIdProvider : IUserIdProvider
{
public string GetUserId(HubConnectionContext connection)
{
return connection.User?.Identity?.Name;
}
}
In case this doesn't work, is there any other way in which one can send SignalR notifications to specific users authenticated with Windows Authentication to an ASP.NET MVC web application? Thanks!