I played with open authentication in MVC5 and SignalR . I use a javascript client to call a simple server method on SignalR and get a response from the server. It works well, but if I add the [Authorize] tag, it will not even call the server method (did not receive a response during debugging).
My assumption was that the server would use an authentication mechanism to challenge the client. Did I miss something? Do I have to manually authenticate the user from the client side, and if so, how can I pass the authentication token?
Here is my hub :
[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()); } }
Here is my Startup.Auth.cs
public void ConfigureAuth(IAppBuilder app) { app.UseGoogleAuthentication(); }
Here's Startup.cs using the code to enable CORS.
public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app);
And finally, this client side code calls the hub method and listens on the RPC server.
this.sendMessage = () => { this.authChat.server.ping(); }; this.authChat.client.pong = (message) => { console.log(message); };
source share