Heya, so I'm running into the 'Invalid Request Signature' error with the JSON API and I'm having a very difficult time getting anywhere.
The API Token that I'm using is set up with both the HMAC signature and timestamp. The error seems to indicate the trouble is with the HMAC signature that I'm generating.
I'm using a javascript backend to generate the POST request body and generate the HMAC (using CryptoJS).
The HMAC generation looks a little like this:
1. Base64 decode the private key string that's generated when the API token is created.
2. Use the CryptoJS HmacSHA256 function with the JSON request body as the message and the base64 decoded private key as the key.
3. Base64 encode the output of #2.
4. Concatenate the different parts of the header: MIVA-HMAC-SHA256 <AccessToken>:<Base64EncodedHMAC>
But this didn't work. Invalid Request Signature.
So I set up a similar process in a PHP Sandbox, using a similar setup to the generateAuthHeader function shown on this page: https://docs.miva.com/json-api/
And I get the same Base64 encoded HMAC as I did with the javascript implementation.
Invalid Request Signature.
Which leads me to think it might be one of the following:
1) To create the JSON request body in the javascript implementation, I use JSON.stringify on an object that's structured in the way required for the API function that I'm using.
For the PHP Sandbox test, I'm using the static string output from JSON.stringify of the POST request object in the javascript implementation.
I'm wondering if there's some issue with using JSON.stringify to generate the POST request body? I'm not entirely sure how the Miva backend is authorizing the passed signature, but if it's doing things like parsing the JSON and re-stringifying it to check the HMAC validity, maybe there's some issues there (e.g., similar to the potential differences between PHP's json_encode and javascript's JSON.stringify()).
2) The docs on https://docs.miva.com/json-api/, specifically the section with the generateAuthHeader function, are wrong. Gasp, how could I suggest a thing - I know, I know, but I only bring it up because Brennan's JSON API Webinar (here: https://vimeo.com/290769714 at the 16 minute mark) says to base64 ENCODE the private key before passing it to the HMAC function, even while the function to the right of the slide (and the docs above) say to decode the private key before passing it to the HMAC function.
Just wondering if anyone here has ran into similar difficulties with the JSON API and can give me a push in the right direction. Thanks for any help!
The API Token that I'm using is set up with both the HMAC signature and timestamp. The error seems to indicate the trouble is with the HMAC signature that I'm generating.
I'm using a javascript backend to generate the POST request body and generate the HMAC (using CryptoJS).
The HMAC generation looks a little like this:
1. Base64 decode the private key string that's generated when the API token is created.
2. Use the CryptoJS HmacSHA256 function with the JSON request body as the message and the base64 decoded private key as the key.
3. Base64 encode the output of #2.
4. Concatenate the different parts of the header: MIVA-HMAC-SHA256 <AccessToken>:<Base64EncodedHMAC>
But this didn't work. Invalid Request Signature.
So I set up a similar process in a PHP Sandbox, using a similar setup to the generateAuthHeader function shown on this page: https://docs.miva.com/json-api/
And I get the same Base64 encoded HMAC as I did with the javascript implementation.
Invalid Request Signature.
Which leads me to think it might be one of the following:
1) To create the JSON request body in the javascript implementation, I use JSON.stringify on an object that's structured in the way required for the API function that I'm using.
For the PHP Sandbox test, I'm using the static string output from JSON.stringify of the POST request object in the javascript implementation.
I'm wondering if there's some issue with using JSON.stringify to generate the POST request body? I'm not entirely sure how the Miva backend is authorizing the passed signature, but if it's doing things like parsing the JSON and re-stringifying it to check the HMAC validity, maybe there's some issues there (e.g., similar to the potential differences between PHP's json_encode and javascript's JSON.stringify()).
2) The docs on https://docs.miva.com/json-api/, specifically the section with the generateAuthHeader function, are wrong. Gasp, how could I suggest a thing - I know, I know, but I only bring it up because Brennan's JSON API Webinar (here: https://vimeo.com/290769714 at the 16 minute mark) says to base64 ENCODE the private key before passing it to the HMAC function, even while the function to the right of the slide (and the docs above) say to decode the private key before passing it to the HMAC function.
Just wondering if anyone here has ran into similar difficulties with the JSON API and can give me a push in the right direction. Thanks for any help!
Comment