Confusion about calculating the Authorization header
-
Hello,
First off, thanks for the making this plugin! I am trying to extend the python wordpress-xmlrpc library to work with your plugin. I think all I need to do is compute and encode the header and pass it along to the server, but when I do so, I get an error that says username and password are invalid.wordpress_xmlrpc.exceptions.InvalidCredentialsError: Incorrect username or password.
This is the bit of python code that sends out the header:
23 def send_request(self, connection, handler, request_body): 24 pk_hash = ba.hexlify(b64.b64encode(hl.sha256(self.private_key+request_body).hexdigest())) 25 auth_header = self.public_key+'||'+pk_hash 26 if (self.accept_gzip_encoding and gzip): 27 connection.putrequest("POST", handler, skip_accept_encoding=True) 28 connection.putheader("Accept-Encoding", "gzip") 29 connection.putheader("Authorization",auth_header) 30 else: 31 connection.putrequest("POST", handler) 32 connection.putheader("Authorization",auth_header) 33
I am not 100% sure I am computing the header correctly – I notice in the example you provide the Authorization header is entirely in hex – the second half is not in the base64 alphabet (as it is in my code)
The header I compute for your example:
req_body= \ '''<methodCall> <methodName>wp.getPosts</methodName> <params> <param> <value><i4>1</i4></value> </param> <param> <value><string></string></value> </param> </methodCall>''' req_body= '<?xml version="1.0?>' + ''.join(req_body.split()) private_key = '7647a19f5bf3e9fd001419900ad48a54' public_key = 'b730db0864b0d4453ba6a26ad6613cd4' hdr = public_key + '||' + b64.standard_b64encode(hl.sha256(private_key + req_body).hexdigest()) print hdr
gives me
b730db0864b0d4453ba6a26ad6613cd4||MGE0MDBlYWQ5YTZlMDQzOTJjYTE2MTY4ODgyY2I4MGI2NTU0YTAxMDZmMDI1NTYxY2U2NmVkOGViNzU0ZWYzZQ==
in constrast to your example which is
b730db0864b0d4453ba6a26ad6613cd4||f0b73fddf91b2358bc28faa745c8c25d3b0d9a36f5456e8181154c54874d81e5
Thanks for any help!
- The topic ‘Confusion about calculating the Authorization header’ is closed to new replies.