Reputation: 3232
I have a complex project consisting of an ASP MVC website, ASP SignalR hub and Xamarin mobile app (all three separate projects). Because the ASP MVC web references the SignalR hub and both are hosted together, there can be only one OWIN Startup class for both projects (otherwise I get an error saying, that there can be just a single OWIN Startup class). And since I use also ASP Identity in the web app, I call the app.UseCookieAuthentication
method, which then requires a cookie before allowing me to communicate with the SignalR hub. Thus the communication between the Xamarin mobile app and the SignalR hub is impossible.
I believe, this question can be answered in two different ways:
response.Cookies[FormsAuthentication.FormsCookieName]
, but FormsAuthentication.FormsCookieName
is not available in Xamarin. How should I create the cookie? And will I be then able to call the web app login method before accessing the SignalR hub?Upvotes: 2
Views: 529
Reputation: 1
It is certainly possible to pass authentication cookies from Xamarin. At some level you're making an http call; http calls can include headers, and a cookie is just a specialized header. Examine the HTTP traffic you have with the interaction that works and note that there should be a header with a name along the lines of .aspnetcookie and value along the lines of name=reallylongstringoflettersandnumbers; you can create an API method that takes in a user and password and authorizes the user, grab the cookie sent back from that request, and include it with any future requests, including the SignalR requests. I'm doing this exact same thing, so feel free to ask for more help if you can't find what you need.
Upvotes: 0