title: SignalR authentication with javascript client
body: <p>I was playing with the <code>open authentication</code> in <code>MVC5</code> and <code>SignalR</code>. I use a javascript client to call a simple server method on <code>SignalR</code> and receive a reply from Server. It works well, but if I add the <code>[Authorize]</code> tag, it does not even call the server method (did not get any response while debugging). </p>
  
  <p>My assumption was the server will use the Authentication mechanism to challenge the client. Am I missing anything? Do I have to manually authenticate the user from the client side and if so how do I pass the authentication token?</p>
  
  <p>Here's my <code>hub</code>:</p>
  
  <pre><code>    [HubName("authChatHub")]
      public class AuthChatHub : Hub
      {
          [Authorize]
          public void Ping()
          {
              Clients.Caller.Pong("Connection is FINE!!");
  
              Clients.Caller.Pong(Context.User == null 
                ? "Null user" 
                : Context.User.Identity.IsAuthenticated.ToString());
          }
      }
  </code></pre>
  
  <p>Here's my <code>Startup.Auth.cs</code></p>
  
  <pre><code>    public void ConfigureAuth(IAppBuilder app)
          {
             app.UseGoogleAuthentication();
          }
  </code></pre>
  
  <p>Here's the <code>Startup.cs</code>, using the code to enable CORS. </p>
  
  <pre><code>public partial class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              ConfigureAuth(app); //added this after a suggestion here, not sure if this is the right place. 
  
              app.Map("/signalr", map =&gt;
              {
                  map.UseCors(CorsOptions.AllowAll);
                  var hubConfiguration = new HubConfiguration
                  {
                      // EnableJSONP = true //empty for now
                  };
  
                  map.RunSignalR(hubConfiguration);
              });
          }
      }
  </code></pre>
  
  <p>And finally this <code>client</code> side code calls the <code>hub</code> method and listens to the server RPC. </p>
  
  <pre><code>this.sendMessage = () =&gt; {
              this.authChat.server.ping();
          };
  this.authChat.client.pong = (message) =&gt; { console.log(message); };
  </code></pre>