- October 23, 2008
- authenticate fcgi fastcgi
- 0 (after 0 ratings)
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
- Run Django as a FastCGI authorizer by cme 6 years, 7 months ago
- view by view basic authentication decorator by Scanner 8 years ago
- Django BasicAuthMixin by icrni 11 months, 2 weeks ago
- Basic Auth Middleware by joshsharp 3 years, 11 months ago
- Login as Any Site user by madhav.bnk 5 years, 5 months ago