Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8d639b7573
Fetching contributors…

Cannot retrieve contributors at this time

file 23 lines (19 sloc) 0.785 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# Custom middleware to handle HTTP_AUTHORIZATION
# Author: A. Pasotti

from django.contrib.auth.models import User
from django.contrib import auth


class HttpAuthMiddleware:
    """
Simple HTTP-Basic auth for testing webservices
"""
    def process_request(self, request):
        auth_basic = request.META.get('HTTP_AUTHORIZATION')
        if auth_basic:
            import base64
            username , dummy, password = base64.decodestring(auth_basic[6:]).partition(':')

            user = auth.authenticate(username=username, password=password)
            if user:
                # User is valid. Set request.user and persist user in the session
                # by logging the user in.
                request.user = user
                auth.login(request, user)
Something went wrong with that request. Please try again.