https://slingdata.io logo
I'm working on an api connection with
# sling-help
b
I'm working on an api connection with HMAC 256. the example is:
Copy code
key = '[ENTER API KEY ID HERE]'
secret = '[ENTER API SECRET HERE]'
url = 'https://www.grantinterface.com/API/DataSet/GetData'

unixtime = time.time()
body = '{"timestamp":' + str(unixtime) + '}'

secretBytes = bytearray.fromhex(secret)
bodyBytes = bytearray(body, "utf8")
signature = hmac.new(secretBytes, bodyBytes, digestmod=hashlib.sha256).hexdigest()

headers = {
    'Content-type': 'application/json',
    'GLM-API-Key': key,
    'GLM-API-Signature': signature
}
It seems the secret is encoded in hex, and need to be decoded from HEX to be used (instead of a string)
bytearray.fromhex(secret)
. Is there a way to specify to sling that the secret encoding is HEX to do the proper conversion?
f
hey @Bruno , this is added for next release! there will be a new
secret_encoding
property. your auth block will look like this:
Copy code
yaml
  authentication:
    type: hmac
    algorithm: sha256
    secret: "{secrets.api_secret}"
    secret_encoding: hex  # decode from hex before signing
    signing_string: "{http_body_raw}"
    request_headers:
      Content-type: "application/json"
      GLM-API-Key: "{secrets.api_key}"
      GLM-API-Signature: "{signature}"
b
awesome! when it's the next release?
f
Targeting end of week.
b
thanks!
3 Views