How to make Django pass cookies when communicating with Node.js server using socket.io? - django

I am currently developing an instant messaging feature for my apps (ideally cross platform mobile app/web app), and I am out of ideas to fix my issue.
So far, I have been able to make everything work locally, using a Node.js server with socket.io, django, and redis, following what most tutorials online suggest.
The step I am now at consists in putting all that in the cloud using amazon AWS. My Django server is up and running, I created a new separate Node.js server, and I am using Elasticache to handle the Redis part. I launch the different parts, and no error shows up.
However, whenever I try using my messaging feature on the web, I keep getting an error 500:
handshake error
I then used the console to check the request header, and I observed that the cookies are not in there, contrary to when I am on localhost. I know it is necessary to authorize the handshake, so I guess that's where my error is coming from..
Furthermore, I have also checked that the cookies do exist, they are just not set in the request header.
My question is then: How can I make sure Django or socket client (not sure who's responsible here..) puts the cookies in the header??
One of my ideas was that maybe I am supposed to put everything on the same server, with different ports, instead of 2 separate servers? Documentation on that specific architecture problem is surprisingly scarce, compared to the number of tutorials describing how to make it work on local.
I hope I described the problem accurately enough! :)
Important note: I am using socket.io v0.9.1-1, only one compatible with a titanium mobile app.
Thank you for any help!

All right, so I've made some progress.
The cookie problem came from the fact I was making cross-domain request, adding a few lines enabled CORS, which didn't solve the cookie issue, but allowed me to communicate between servers (basically I set the headers of the response using express. I then passed necessary data in the query, even if not the most secure way to do it, I'm just building an MVP, and it's enough for now.
I haven't been able to make the chat work from my Titanium mobile app, but since I can use a webview to handle it, I will be fine.
Hopefully that will help someone.. If anyone needs me to post some code snippets I will gladly do so upon request!
Cheers

Related

Meteor js - client view doesnt update (AWS Lightsail + Nginx reverse proxy)

My Meteor app doesnt want to work properly when uploaded to AWS Lightsail.
The problem is - when I update a document in collection the changes are not reflected on the client, and even more strange - the updated variable disappears from the client view.
Everything works well in development on my local machine though. I also had the same app deployed to my office server machine and was running without any issues.
I created simple script to reproduce the problem, see on the vid: https://streamable.com/mnu26j
So adding or removing document reflects without issue on the client side, but when I try to edit a variable (name) - it saves it to the database, but the client doesnt the reflect the change until I refresh the page.
To me it feels like there might be some problem with maybe wrongly configured websocket connection that doesnt work together with AWS services, but I might be totally wrong on that. In the full version of the app the websocket was constantly reconnecting and closing connection when I tried to authenticate the user (in a cycle of few hundred times per minute) and the app was stuck on log in screen.
Maybe someone has already met a similar problem or at least would have some clue where I could look for a cause of it?
Let me know if you want me to provide any more details.

Cloning PyQt app in django framework

I've designed a desktop app using PyQt GUI toolkit and now I need to embed this app on my Django website. Do I need to clone it using django's own logic or is there a way to get it up on website using some interface. Coz I need this to work on my website same way it works as desktop. Do I need to find out packages in django to remake it over the web or is there way to simplify the task?
Please help.
I'm not aware of any libraries to port a PyQT desktop app to a django webapp. Django certainly does nothing to enable this one way or another. I think, you'll find that you have to rewrite it for the web. Django is a great framework and depending on the complexity of your app, it might not be too difficult. If you haven't done much with web development, there is a lot to learn!
If it seemed like common sense to you that you should be able to run a desktop app as a webapp, consider this:
Almost all web communication that you likely encounter is done via HTTP. HTTP is a protocol for passing data between servers and clients (often, browsers). What this means is that any communication that takes place must be resolved into discrete chunks. Consider an example flow:
You go to google in your browser.
Your browser then hits a DNS server (or cache) that resolves the name google.com to some IP address.
Cool, now your browser makes a request to that IP address and says "get me some stuff".
Google decides to send you back a minimal amount of HTML and lots of minified JavaScript in the page.
Your browser realizes that there are some image links in the HTML and so it makes additional requests to google to get each of the images so that it can display them.
Now all the content is loaded on your browser so it starts to execute the JavaScript code, and that code needs some more data from google so it starts sending requests to google too.
This is just a small example of how fundamentally different a web application operates than how a desktop application does. On a desktop app you have the added convenience that any operation doesn't need to be "packaged up" and sent, then have an action taken, etc (unless you're using a messaging architecture, but that's relatively uncommon outside of enterprise apps).

webservice authentication and user identity management

My team and me are currently working on quite a large project. We are working on an online game, which will be accessible (for the moment), in two ways:
-Via a web browser, an application full JavaScript(client-side), full Ajax (basically meaning that the UI will be managed in JS client side).
-Via an iPhone application (the UI will be managed by the application itself).
Between the two different applications, the core logic remains the same, so I believe (I could be wrong), that the best solution would be to create a web service (if possible using standards such as RESTful or Rest) capable of perming all necessary operations.
Following this logic, I have encountered a problem: the authentication and identity management of the user. This poses problem as the applications users need to be authenticated to preform certain operations.
I’ve looked into WS-security, but this obviously requires passwords to be stored, unencrypted on the server, which is not acceptable!
I then looked into Oauth, but at first glance this seemed like a lot of work to set up and not particularly suited to my needs (the way that applications have to be accepted does not please me since it will be my application and my application only using the web service, not any external application).
I’ve read and heard about a lot of other ways to do what I want, but to be honest, I’m a little confused and I don’t know what information is reliable and what isn’t.
I would like to note that I’m using symfony2 for the backend and jquery for the client side JavaScript.
Furthermore, I would like a detailed, step-by-step response, because I really am confused with all that I have read and heard.
Thank you for your time, and I hope someone can help me as it’s quite urgent.
Good evening
I'm not entirely sure if this answers your request, but since the UI will always be handled on the client side, I think you could use stateless HTTP authentication:
This is the firewall in security.yml:
security:
firewalls:
api:
pattern: ^/api/ # or whatever path you want
http_basic: ~
stateless: true
And then the idea basically is that on the server, you use your normal user providers, encoders and whatnot to achieve maximal security, and on the client, you send the HTTP authentication headers, for example, in jQuery:
$.ajax("...", {
username: "Foo",
password: "bar"
});
Please note that since the authentication is stateless (no cookie is ever created), the headers have to be sent with every request, but, I figure, since the application is almost entirely client-side, this isn't a problem.
You can also check the Symfony2 security manual for further information on how to setup HTTP authentication. Also be sure to force HTTPS access in your ACL, so the requests containing the credentials are secured (requires_channel: https in your ACL definitions).

Best practices to update a live web service

I am always curious about how large-scale live web application updates are done. Since the application is live, that is why it complicates everything -you should not down your service and at the same time you should recover the activity/changes (in database etc.) made on your site to the new version during the update later on.
The first and most natural technique comes to the mind is that redirecting all the requests to some other replicated server, so that you can update original server without shutting-down your service.
I just wonder is there any other smarter techniques to handle updates in a live web service. Please, share your experience and opinions guys!
I am facing the same challenge myself.
What i did was to recreate the web page on another server [lets name it Test server] (with a different domain of course), import the scripts/database from live server and adjust them on the new domain.
Now I am experimenting on the Test server and after i make sure that everything is working OK, i am pushing the changes to the live server.
Unfortunately, i dont know if this is the correct way to do this. You have to be careful but it works.

Building web services without a web server

OK, this is impossible, but I will try to explain the situation here.
Let's say we have cases, that we need a fast setup of a web server in order to have a simple soap web service running (querying a db and so on).
In VS though, upon debugging a web project, it creates a quick ASP.NET development server without relying on the actuall IIS that might be installed on the PC.
Is there any project that does something like that?
This would be ideal for small projects, where a simple executable would get a server ready to go and would allow web services to be executed right away.
I have looked at some stuff over the net like http://msdn.microsoft.com/en-us/magazine/cc163879.aspx and http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2004/05/24/4479.aspx but they seem to be quite outdated and i am not sure how well they work (havent tested them thoroughly)
EDIT: I have build an application like the one you suggest. However, how can i implement HTTP GET/POST requests to the service using this method? I tried using WebGet after my operationcontract but it didnt work. For example, my service is at http://localhost:8080/Service and i would like to use it such as http://localhost:8080/Service/getMethod?x=2.
I believe that the development server used by Visual Studio is based off of the Cassini code base (of which there is a fork here). I also found this article on hosting the asp.net runtime. It was also created a while back (2004), but has been updated since (2008). I think a lot of the core concepts are probably still the same.
Another approach would be a roll-your-own web server using the HttpListener class. This could take some work if you want to use it for hosting asmx type services, but if you were doing RESTful services, it isn't too bad of an option (this is actually how RavenDB works if you are not hosting it under IIS).
A WCF service can be hosted in almost any kind of application, including a Windows Service or a console application. There is no need for a web server at all.
Alright,
i've done it so im posting it here to help anyone who has issues with similar problems.
Create your WCF Service file as usual and then by using ServiceHost (or WebServiceHost) you can easily create a WCF service.
In order to use GET http requests to make it simple to communicate with mobile devices (such as iphone) you can use WebGet above your service methods and make sure you manually add a service endpoint using WebHttpBinding for WebServiceHost or WebHttpBinding with an WebHttpBehavior for ServiceHost.
Then you can call your service methods such as http://localhost:port/webhttpendpointaddress/mymethod?x=2.