This is a basic view for a FastCGI authorizer against the Django auth. The idea is to return either a blank response with REMOTE_USER set on success, a forbidden response for failure, or a redirect to a login page when no user is logged in.
I use this view for a Trac instance running on the same (lighttpd) server as Django. lighttpd is set up to use Django as a FastCGI authorizer (using snippet 1149) for the Trac URLs instead of using basic/digest HTTP authentication, so Trac has the same users as Django.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
def auth(request, path): from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden from django.utils.html import escape if request.user.is_anonymous(): # If not logged in, redirect to login page return HttpResponseRedirect(reverse("login") + "?next=/" + escape(path)) elif request.user.has_perm("some.perm"): # If allowed, then return empty "200 OK" response, and # set REQUEST_USER. result = HttpResponse() result['Variable-REMOTE_USER'] = request.user.username return result else: # Otherwise, a user who isn't allowed. result = HttpResponseForbidden() result.write("Access denied") return result
More like this
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 1 month ago
- Python Django CRUD Example Tutorial by tuts_station 1 month, 2 weeks ago
- Browser-native date input field by kytta 2 months, 4 weeks ago
- Generate and render HTML Table by LLyaudet 3 months, 1 week ago
- My firs Snippets by GutemaG 3 months, 1 week ago