5
votes

I have been researching this for a while and cannot seem to figure it out.

I have a .NET SignalR Client that needs to be authenticated with ASP.NET Identity (MVC5) so that it can access SignalR hubs secured with the [Authorize] attribute.

I found the following resource (Please see Authentication options for .NET Clients / Cookie):

http://www.asp.net/signalr/overview/signalr-20/security/hub-authorization

However the code sample for retrieving the cookie doesn't work due to:

authCookie = response.Cookies[FormsAuthentication.FormsCookieName];

and as I am not using Forms Authentication this produces an error.

I am unsure how to change this for ASP.NET Identity?

Am I focused on the correct approach, ie. retrieving a cookie and then adding it to the Cookie Container? or should I be passing the Username and Password in headers to a Hub and authenticating somehow this way?

I did not realise how confusing it would be to authenticate using a .NET client with SignalR and Identity Framework.

Even though it is not my use case I am also tagging the question with Xamarin as I feel this might be an issue faced by Xamarin mobile developers using the SignalR .NET client also.

As I cannot seem to find any examples on the Internet, any assistance would be much appreciated. Thanks.

1
and how you get it at all? i put authorize, then using MVC5, i log in, it still tell me unauthorize... also there is no code preview, for first part which uses AuthorizeAttribute, to tell what to do other than putting this attribute, ... to be able to authorize or unauthorize a client.deadManN

1 Answers

1
votes

Just change this

var authCookie = response.Cookies[FormsAuthentication.FormsCookieName];

to

var authCookie = response.Cookies[".AspNet.ApplicationCookie"];