2

I have an Azure WebRole (MVC app) and Azure Worker role.

Now, I have my SignalR hubs hosted in the Worker Role using Owin.SelfHost.

The MVC app need to call this hubs in the worker role - which is quite straightforward.

Now my problem is authentication.

I need to access the WebRole's Context.User.Identity on the webrole so that I can still authenticate the calls to my hubs.

Worker Role

  public class MyHub: Hub
{
  public override Task OnConnected() {
        var id = Context.User.Identity.Name; // NULL
        var connectionId = Context.ConnectionId;
  }

  [Authorize] 
  public void SendMessage() ....    
}

Currently - im stuck with this

 public void Configuration(IAppBuilder app)
    {

     app.Map("/signalr", map =>
        {
            map.Run(async context =>
            {
                var userName = context.Request.Query["user"]; //NULL
                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.Name, userName));
                context.Authentication.SignIn(identity);
            });

           .....
        });

}

Somehow, I need to pass the User.Context (Asp.net identity) from my WebRole to the Owin Pipeline in the worker role.

Any idea how to do that?

Linc Abela
  • 797
  • 2
  • 12
  • 26
  • Anyone who can help? – Linc Abela Sep 25 '14 at 07:20
  • is the web site and signalr self host in the same domain? You may be able to share the cookie between them just by setting the path of the cookie. I didn't list as the answer as there will be a couple of dragons in there. – Philip Nelson Sep 25 '14 at 15:08
  • yes it is in the same domain, the website is in port 80 and using CookieAuthentication and ASP.NET Identity hosted in IIS while the SignalR is in port 8088 which OWIN self hosted in worker role. Can you give me pointer how can I share the cookies between the applications? – Linc Abela Sep 25 '14 at 23:33
  • check this answer out. Even if it is out of date the terms should make for good googling. http://stackoverflow.com/questions/19166599/asp-net-identity-cookie-across-subdomains – Philip Nelson Sep 26 '14 at 00:24

1 Answers1

0

the SignalR implementation at the link below, should answer your question.

you can take a close look at the Attribute that decorates the hub class and take a look at the implementation.

you can also look at the GetCurrentUserName in the Hub class itself.

https://github.com/louislewis2/AngularJSAuthentication

Louis

Louis Lewis
  • 1,298
  • 10
  • 25