Search code examples
restpython-3.xeve

eve framework and HMAC auth


I'm computing the HMAC of the HTTP body request in this way:

payload = {"name":"myvm","os":"gentoo","resources":{"vCPU":"4","RAM":"512","Disk":"1000"},"actions":["start"]}

key = "supersecretkey"
secret = bytes(key, encoding='utf-8')

msg = json.dumps(payload, sort_keys=True)
message = bytes(msg, encoding='utf-8')

print(hmac.new(secret, message, sha1).hexdigest())

After that I encode with b64 the hexdigest and send it with curl like the docs says Authorization: paolo:$hmac_base64_encoded
The problem is that I always get a 500 error.
What am I doing wrong?


Solution

  • Since you are using Python 3x make sure that in your custom HMACAuth you are converting to bytes (the code snippet from the official documentation is for Python 2x).