Welcome! Log In Create A New Profile

Advanced

[WD26] Signature for REST request

Posted by ArieM 
[WD26] Signature for REST request
January 15, 2022 09:23PM
Hi, I need a signature for a REST request, based on info of the request (timestamp, method, url and body) together with my APIKEY

The documentation says:
A signature is generated by creating a SHA256 HMAC hex digest of timestamp + method + url + body.
timestamp+method+url+body are no problem, these are just params of the request

A Python example looks like this
def createSignature(timestamp, method, url, body, APISECRET):
  string = str(timestamp) + method + '/v2' + url
  if(len(body.keys()) != 0):
    string += json.dumps(body, separators=(',',':'))
  signature = hmac.new(APISECRET.encode('utf-8'), string.encode('utf-8'), hashlib.sha256).hexdigest()
  return signature

Timestamp, method, url, body are all known and put together in 'string'
But I'm struggling with the final step

So what is the Windev equivalent of
signature = hmac.new(APISECRET.encode('utf-8'), string.encode('utf-8'), hashlib.sha256).hexdigest()

Arie
Argus
Re: [WD26] Signature for REST request
January 15, 2022 11:12PM
you are simply looking for the HASH function one of its parameter should match your example
Re: [WD26] Signature for REST request
January 16, 2022 02:41PM
Thanks, got it working now. I missed the 2nd syntax in the help WITH the secret-key option.
I also had to add a call to BufferToHexa() to get the "hex digest" of it.

Arie
Re: [WD26] Signature for REST request
January 16, 2022 09:02PM
For those interested, this is the final working code

sHash is string = HashString(HA_HMAC_SHA_256, sMessage, m_sApiSecret)
sHash = BufferToHexa(sHash, NoGrouping, NoLine)
sHash = Lower(sHash)

Arie
Re: [WD26] Signature for REST request
January 16, 2022 09:05PM
And credits to Peter (HoBe) for pointing someone on the French forum to this post smiling smiley

Arie
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: