<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I need to authenticate users using basic HTTP 
authentication and the code below works on Mozilla, Opera, that awful KDE 
browser ;-) and whatever else I throw at it, EXCEPT MSIE. Most of my potential 
users are MS IE addicts so this is a key point in my project. The code below are 
ported from a previous project based on BaseHTTPServer. It might be that I 
didn't send a end_headers-header before sending the plain-text content. This was 
done in the BaseHTTPServer-solution, but I didn't find any such code in 
Twisted.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; def render(self, 
request):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; username = 
request.getUser()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; password = 
request.getPassword()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not 
username or not 
password:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
request.setResponseCode(401, 'Authentication 
needed')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
request.setHeader('Connection', 
'close')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
request.setHeader('WWW-Authenticate', 'Basic realm="%s"' % 
'default')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
request.setHeader('Content-Length', str(len('401: Authorization 
needed.')))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
request.setHeader('Content-Type', 
'text/html')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return '&lt;h1&gt;401 Authentication required&lt;/h1&gt;%s' % msg</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; # else process the request in a 
normal way<BR></DIV></FONT>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>How can I use Twisted to authenticate users using 
basic HTTP authentication? Are there any example on how to use the cred-module 
in Twisted to authenticate users? </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any information on this issue would be highly 
appreciated. Ideas on how to maintain user-information and implement security 
policies in Twisted, especially web-based Twisted-apps are also very 
interesting.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Best regards,</FONT></DIV>
<DIV><FONT face=Arial size=2>Thomas Weholt</DIV></FONT></BODY></HTML>