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?

4

1 回答 1

0

下面链接中的 SignalR 实现应该可以回答您的问题。

您可以仔细查看装饰中心类的 Attribute 并查看实现。

您还可以查看 Hub 类本身中的 GetCurrentUserName。

https://github.com/louislewis2/AngularJSAuthentication

路易斯

于 2014-10-21T20:32:06.080 回答