Apache, mod_wsgi & django rest-framework, RESTEasy

(0 comments)

So .. I just spent way too much time figuring out why my django-rest-framework did not work with authentication enabled .. As usual turns out it was simple: the culprit was mod_wsgi and it's default settings:

All I had to do was set this option in my apache config:

WSGIPassAuthorization On

before that I kept getting this error: {"detail":"Authentication credentials were not provided."}

Who would've thought that was Off by default .. also it seems to be a good idea to pass --basic with --user <user>:<pwd> with curl to make sure it uses basic auth.

On the plus side I did also look into Token based auth for the django rest framework which I find to be more useful than basic auth when using from RESTEasy

One thing about RESTEasy & Token based auth is that one needs to set the header manually (the instad of providing auth=('user','pwd') to resteasy.RESTEasy(...)

so it goes something like this:

from resteasy import RESTEasy, json


api = RESTEASY(base_url=<baseurl>, encoder=json.dumps, decoder=json.loads, <other options as needed>)
api.session.headers['Authorization'] = 'Token <token>'

data = api.route('bla/')
...

Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

Recent Posts

Archive

2018
2014
2012
2011
2010
2009
2008
2007

Categories

Authors

Feeds

RSS / Atom