On Mon, Jan 20, 2014 at 7:51 AM, Alexey Gusev <gusev.alexe...@gmail.com> wrote: > Im developing small intranet web service. I want authenticate users over > kerberos in MS AD or with basic auth. For that reason i need to set two > 'WWW-Authenticate' http headers in response 401. How can i do it with Django > ? > > Should be something like this: > > Client: GET www/index.html > > Server: HTTP/1.1 401 Unauthorized > WWW-Authenticate: Negotiate > WWW-Authenticate: Basic realm="corp site" > > This code overwrite header: > > def auth(request): > response = None > auth = request.META.get('HTTP_AUTHORIZATION') > if not auth: > response = HttpResponse(status = 401) > response['WWW-Authenticate'] = 'Negotiate' > response['WWW-Authenticate'] = 'Basic realm=" trolls place basic > auth"' > > elif auth.startswith('Negotiate YII'): > ... > > return response >
Impossible to do with base classes, but django allows you to customize your responses however you like: class MultiAuthResponse(HttpResponse): www_auth_headers = [ ] def serialize_headers(self): base_headers = super(MultiAuthResponse, self).serialize_headers() extra_headers = '\r\n'.join([ 'WWW-Authenticate: %s' % hdr.encode('us-ascii') for hdr in self.www_auth_headers ]) return base_headers + extra_headers response = MultiAuthResponse(status=401) response.www_auth_headers = [ 'Negotiate', 'Basic realm="trolls place basic auth"' ] Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1Jq2d6G77LZxJV%2BzS%3DxZt%3DKS_hXCVZ1e%3Dj2tdgCTepRZA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.