2

Trying to implement signalR into our project.

Currently, have a working version without authentication, the server and client talking successfully via websockets.

All good so far!

The next step was to add the user login id to match to the connection id, this is what I cant figure out.

A user logs into the site, gets to the authenticated page with the HttpContext.User set to our version of iprinciple, which contains various bits of data specific to that user.

This is available to the normal MVC controller for page posts and ajax calls, but not to the Hub controller (my name of where the signalr methods are called).

using something like this:

protected object GetAuthInfo()
{
    var user = Context.User;
    return new
    {
        UserName = user.Identity.Name
    };
}

However, this Context.User.Identity is null and Context.User is not authorised. It seems to me that the websocket is on a different session and has no knowledge of the initial page load session so no user identity has been setup.

TheBoyan
  • 6,802
  • 3
  • 45
  • 61
WoofWoof88
  • 1,107
  • 1
  • 8
  • 11
  • 1
    Try this quesiton, see if it helps: http://stackoverflow.com/questions/20522477/no-access-to-the-session-information-through-signalr-hub-is-my-design-is-wrong – TheBoyan Dec 31 '15 at 14:27

1 Answers1

2

Do you have also required authentication for all hubs and hub methods in your application by calling the RequireAuthentication method when the application starts ?

public partial class Startup {
  public void Configuration(IAppBuilder app) {
    app.MapSignalR();
    GlobalHost.HubPipeline.RequireAuthentication();
 }
}

(extract from http://www.asp.net/signalr/overview/security/hub-authorization)

Hope this helps Happy new year ! Best regards Stéphane

stephgou
  • 199
  • 2
  • Yes, using this in Startup. When the browser tries to load the "signalr/hubs", it fails with a not authorised response (tries to return to the login screen via returnurl ), even though to get to that page where the signalr/hubs is requested, you have to login to the site using forms authenication. – WoofWoof88 Jan 04 '16 at 13:33
  • i have the same problem over here. – DLL_Whisperer Nov 08 '18 at 08:58