title: Authorization in SignalR 2.0
body: <p>I have a Web server with forms authentication and another server that hosts the SignalR Hubs. Using the forms authentication cookie I want to extract the current user using the code below. This would be possible using a HttpModule, but when using SignalR a HttpModule cannot be used. </p>
  
  <p>Is there any other way to archive what I want to do?</p>
  
  <pre><code>public class AuthorizationHubModule : HubPipelineModule
  {
      public AuthorizationHubModule()
      {
      }
  
      protected override bool OnBeforeConnect(IHub hub)
      {
          var cookies = hub.Context.Request.Cookies;
          if (cookies.ContainsKey(".ASPXAUTH") == true)
          {
              // Get the user, populate the Thread.CurrentUser...
              Cookie cookie = cookies[".ASPXAUTH"];
  
              if (cookie != null)
              {
                  FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
  
                  GenericIdentity identity = new GenericIdentity(ticket.Name);
                  GenericPrincipal principal = new GenericPrincipal(identity, new string[0]);
  
                  // Cannot do this because User is readonly (this is possible in a normal HttpModule)
                  //hub.Context.User = principal;
              }
          }
  
          return base.OnBeforeConnect(hub);
      }
  }
  </code></pre>
  
  <p>The thing we are after, is to set the IPrincipal associated with SignalR.</p>