When you call a web service like this:
username = 'test12'
password = 'test34'
client = httplib2.Http(".cache")
client.add_credentials(username,password)
URL = "http://localhost:8080/wyWebServiceTest"
response, content = client.request(URL)
How do you get the username/password into variables on the server side (i.e. in the web-service that I'm writing). I checked the self.request.headers and self.request.environ and couldn't find them.
(I'm not using Google Login, need to bounce this userid/pass against my own database to verify security.)
I was trying to ideas from this page: http://pythonpaste.org/webob/reference.html#headers
Thanks,
Neal Walters
Slight enhancement to Peter's code below:
auth = None
if 'Authorization' in self.request.headers:
auth = self.request.headers['Authorization']
if not auth:
httplib2 will only pass the credentials after a 401 response from the web server, after which the credentials should be sent in an Authorization: header.
I haven't tested this code (insert smiley) but I think this is the sort of thing you need. Basically your credentials won't be in the header if your server hasn't bounced a 401 back to your client (the client needs to know the realm to know what credentials to provide).
The credentials will appear in the Authorization header. The steps work like this:
The exact content of the client's Authorization header in step 3 depends on the authorization method used. For HTTP Basic auth, it's the base64-encoded user credentials - see here. For HTTP digest auth, both the server's header and the response from the client are a bit more complicated - see here.