Hello,<br><br>With Twisted and Nevow I'm building an XML-RPC server that does HTTP authentication. So a basic XML-RPC client can login using <a href="https://user:passwd@host">https://user:passwd@host</a>. I can get the credentials with HTTP authentication, but how can I check the credentials. I'd tried calling
guard.SessionWrapper.login(....), but I get the error: "<a name="tracebackEnd">exceptions.TypeError: unbound method login()
must be called with SessionWrapper instance as first argument (got
NevowRequest instance instead)".<br><br>So I'm guessing that request.getSession() is wrong and I must get the session of the guard (or something similar). Or I'm calling the wrong function to check the creds. In the guarded.py example from Nevow the credentials get checked thru a html form, but that is not what I want.
<br><br>Below is an example part of my code:</a><br><br>class RootPage(rend.Page):<br> ## We are a directory-like resource because we are at the root<br> addSlash = True<br> ## Doesn't work<br> def tryLogin(self, ctx, request):
<br> session = request.getSession() <br> segments = inevow.ICurrentSegments(ctx)<br> httpAuthCredentials = (self.data_username,self.data_password)<br> return guard.SessionWrapper.login(request, session, httpAuthCredentials, segments).addCallback(self._loginSucceeded).addErrback(
self.loginFailed)<br><br> def renderHTTP(self, ctx):<br> request = inevow.IRequest(ctx)<br> username, password = request.getUser(), request.getPassword()<br> ## No REAL authentication yet, must implement it.
<br> if (username, password) == ('', ''):<br> request.setHeader('WWW-Authenticate', 'Basic realm='+cfg.app_name)<br> request.setResponseCode(http.UNAUTHORIZED)<br>
return "Authentication required."<br> ## They provided a username and password, so let's let them in! horray<br> self.data_username, self.data_password = username, password<br><br>
self.tryLogin(ctx, request)<br> return rend.Page.renderHTTP(self, ctx)<br><br> docFactory = loaders.stan(tags.html[<br> tags.body[<br> tags.h1["Welcome user!"],<br> tags.div["You said: ",
<br> tags.span(data=tags.directive('username'), render=str),<br> " ",<br> tags.span(data=tags.directive('password'), render=str),<br> tags.a(href=guard.LOGOUT_AVATAR
)["Logout"]<br> ]]])<br><br>Regards,<br><br>Kim Chee Leong<br><br>