Simon Willison’s Weblog


Turn your Django application in to an OpenID consumer

24th April 2007

I’ve just put the finishing touches on the first releasable version of django_openidconsumer, a package that makes it easy to add OpenID consumer support to any Django application.

Full documentation can be found in the repository. The package consists of Django models that implement the persistent part of an OpenID consumer, some simple views that hook in to the python-openid library from OpenID Enabled and a piece of middleware that makes the user’s OpenID(s) directly available within a Django view.

To cut a long story short, it allows you write view functions that look like this:

def example_view(request):
    if request.openid:
        return HttpResponse("OpenID is %s" % escape(
        return HttpResponse("No OpenID")

The package also supports simple registration, which lets you request additional details such as an e-mail address or nickname from the user’s OpenID provider.

I plan to keep the package under active development, with the aim of using it to demonstrate best practises in implementing OpenID (hence the support for multiple OpenIDs and simple registration out of the box). Next on the list is integration with Django’s built in authentication system, including the ability to associate one or more OpenIDs with an existing user account.

Please post any feedback as a comment on this entry, and direct bug reports to Google Code.