1 # -*- coding: utf-8 -*-
2 from django_authopenid
import mimeparse
3 from django
.http
import HttpResponseRedirect
4 from django
.core
.urlresolvers
import reverse
6 __all__
= ["OpenIDMiddleware"]
8 class OpenIDMiddleware(object):
10 Populate request.openid. This comes either from cookie or from
11 session, depending on the presence of OPENID_USE_SESSIONS.
13 def process_request(self
, request
):
14 request
.openid
= request
.session
.get('openid', None)
16 def process_response(self
, request
, response
):
17 if response
.status_code
!= 200 or len(response
.content
) < 200:
19 path
= request
.get_full_path()
20 if path
== "/" and request
.META
.has_key('HTTP_ACCEPT') and \
21 mimeparse
.best_match(['text/html', 'application/xrds+xml'],
22 request
.META
['HTTP_ACCEPT']) == 'application/xrds+xml':
23 return HttpResponseRedirect(reverse('yadis_xrdf'))