Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use HTTP Basic Authentication with Django?

We have a website running on Apache, access to which has a number of static pages protected via HTTP Basic authentication.

I've written a new part of the site with Django using Django's built in support for user management.

The problem I have is that users have to log in once via the HTTP Basic authentication and then again using a Django login form. This both clumsy and very confusing for users.

I was wondering if anyone had found a way to make Django log a user in using the HTTP Basic authentication information.

I not expecting to pass a password to Django, but rather if a user dave has been authenticated by Apache then they should be automatically logged into Django as dave too.

(One option would be to make Apache and Django share a user store to ensure common usernames and passwords but this would still involve two login prompts which is what I'm trying to avoid.)

like image 997
Dave Webb Avatar asked Sep 30 '08 08:09

Dave Webb


1 Answers

For just supporting basic auth on some requests (and not mucking with the web server -- which is how someone might interpret your question title), you will want to look here:

http://www.djangosnippets.org/snippets/243/

like image 109
wsorenson Avatar answered Sep 17 '22 02:09

wsorenson