Django REST Knox Authentication Issues - django

I've completed the development work on a Django REST API using Knox-Rest. It works great in my development environment but after moving it to the Prod environment, it authenticates users and returns a token back. Then using Postman, to test the API, I execute a GET using the returned token, I get a 401 error, Credentials Not Provided.
Looking at the "knox_authtoken" table, I see separate rows for each login. On the same table in development, I just see one row per user. I believe the answer to why it's not working is related to what I'm seeing on the table but I'm not sure what it's telling me.
All of the code is identical so it's likely in the setup but I can't seem to track it down. So anyone with some experience with the Django Knox-REST API that might have some ideas, I'd really appreciate it.

If Django is behind an Apache Webserver you'll need to enable WSGIPassAuthorization

Related

Problem in hosting Django REST API on IIS

I was trying to host django REST API on IIS but it wasn't working properly. I worked with the same locally and it was working absolutely fine.
But when I hosted it on IIS then first of all its homepage with get method for all data from the database takes longer time to load and ended up with timeout error. And, when I tried to access other pages, the same problem occurred with them too. Only a page with post method opened but when I tried to submit data it raised an error.
I checked server configuration then I found that default error is timeout error. Now I am confused about why such things happened.
Can anyone please tell me if they faced similar issue or if they know some kind of compatibility issue or some prerequisite for hosting REST API using Django REST Framework? Or help me how can I find and fix the issue.
Are you using FastCGI? check the Authentication then try to disable windows authentication and enable anonymous authentication, try that if it will work.

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

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

Authentication with apache2 php pages and tomcat REST calls

Hello smart people on stackoverflow,
I would be very happy if someone could point me to the right libraries/frameworks to do what I want.
We have the following web architecture set up.
1. We have a tomcat server that offers REST services.
2. We have an apache2 server that serves up php pages to users.
a. Some of these php pages make REST calls to tomcat for data.
b. Other php pages contain javascript that makes REST calls that are routed through apache2 via mod_proxy to tomcat. e.g. All request to http://myapache.com/PASSTOTOMCAT/rest/getSecureData would go to tomcat.
Now, I'm asked to add authentication to everything, both the user pages as well as the REST calls. It would obviously be ideal for the user to sign-in once for access to both.
What library can I use for this? I don't think I can use any php-based solution (ie. one that involves adding a ) because the pass-through url's won't have a chance to add this code and check for authentication. I think I need to use something built into apache2 itself.
One minor requirement is that I would like the user credentials stored in a mysql database as opposed to a file.
Am I over-thinking this?
Thanks in advance
Well it's been 5 days, so I guess I'll answer my own question...
I ended up using the new mod_auth_form for authentication because it lets you use a nice stylized webpage to log users in.
I also used mod_dbd to access user credentials in mysql.
I couldn't find a nice tutorial on this so I struggled through the installation and setup a bit, but if anyone cares, I created a set of instructions on my blog in case anyone else tries to do the same thing.
Installation
Setup

How to use NowJS to provide notifications to user in django framework

I have built a website in django framework. It has a lot of features such as blog, discussion forum, basically there are lots of ways users can interact. I have built a basic notification framework where a user gets notified when somebody comments on their blog, or answers their question in the forum.
Since the notifications are stored in db, new notifications are displayed only when a page refresh is done. I would like to make it real time using some push server using something like long polling technique.
I have come across NowJS which seems to be pretty handy for this, but in all the examples that are given I could not see any example where there was any interaction with the database. In all the cases there was some information sent by one client and it was displayed to one or more clients.
What I actually want to do is to call a function using NowJS, and make it go to sleep until a new notification is added in the database. When a new notifications comes in the server responds back with the notification and a new request is done immediately.
I can figure out all other parts except how to access the database from Node server that is used by NowJS. Any help or guidance is appreciated.
Either:
Have your node.js server make an http call to the Django server via something like a REST api to get info back
Google for a database connector for node.js - I found enough evidence for a MySQL one, and rumours of a PostgreSQL one. Note this won't get you access to the Django DB API, so you'll have to work out all your related queries and craft your SQL by hand (make sure Bobby Tables doesn't bother you: http://www.xkcd.com/327)
Re-implement the NowJS protocol so that you can write a django server for it, keeping the same JS client code on the clients... but then you may as wel.....
...use django-socketio http://blog.jupo.org/2011/08/13/real-time-web-apps-with-django-and-websockets/

Accessing a django-piston REST API via a django view within the same project

I'm building a small web service. To showcase what the service can do I am going to build a lite-weight interface. I'm having a hard time figuring out how my REST API and regular Django views can play nicely together.
Here's my setup:
Using django-piston to build a simple CRUD REST web service.
Using Django views with httplib2 to GET/POST to/from that web service.
Both are being run from the same Django project (and thus same web server).
Right now I have simple read REST service working in the browser. But when I try to use httplib2 from the Django view the request just hangs.
My questions:
-Am I thinking about this the right way?
-Is there a better way to accomplish this?
-Should my REST web service be a different project (and web server) than my REST interface?
Any help would be greatly appreciated!
Generally, I'd demonstrate an API working via unit tests, rather than live views, but can see how that might not be what you need.
So (in line with akonsu's comment above) if you're experiencing this problem local dev, it's the single threaded devserver that's blocking the API from running while the view is executing.
Have you tried a multi-threaded version of the runserver? Like this one?