INVALID_SIGNATURE

Archived from the Transloadit support forum. Originally posted on March 4, 2014; details may be outdated, see our docs for current behavior. Original thread

Hi, I’ve followed the instructions in the API docs and I’m using the example PHP code for creating the signature but I get an INVALID_SIGNATURE error:

$authKey    = 'REDACTED';
$authSecret = '<my-secret>';
$expires = gmdate('Y/m/d H:i:s+00:00', strtotime('+1 hour'));
$params = json_encode(array(
    'auth' => array(
    'expires' => $expires,
    'key'     => $authKey
  )
));
$params = str_replace('\/','/', $params);
$signature = hash_hmac('sha1', $params, $authSecret);

And the I add the signature field to the request (or as a hidden field in form) but always get INVALID_SIGNATURE. What am I doing wrong??

The javascript looks like this:

$(function() {
  // We reference our html form here
  $('#upload-form').transloadit({
    // We want to wait for all encodings to finish before the form
    // is submitted.
    wait: true,
    // The upload to Transloadit should start as soon as the user
    // selects some files.
    triggerUploadOnFileSelection: true,

    signature: "<?php echo $signature?>", 
    params: {
      auth: {
        // This is your API key.
        key: "REDACTED",
        expires: "<?php echo $expires ?>"
      },
      // Our assembly instructions just contain two steps for now.
      // You can name the steps how you like.
      steps: {
        // The first step resizes the uploaded image(s) to 125x125 pixels.
        // The /image/resize robots ignores any files that are not images
        // automatically.
        resize_to_125: {
          robot: "/image/resize",
          use: ":original",
          width: 125,
          height: 125
        },
        // The second step resizes the results further to 75x75 pixels.
        // Notice how we "use" the output files of the "resize_to_125"
        // step as our input here. We could use all kinds of steps with
        // various robots that "use" each other, making this perfect for
        // any workflow.
        resize_to_75: {
          robot: "/image/resize",
          use: "resize_to_125",
          width: 75,
          height: 75,
          // We also add a sepia effect here just for fun.
          // The /image/resize robot has a ton of available parameters.
          sepia: 80
        }
      }
    }
  });
});

Nevermind, found out what I did wrong.

Hey Harald, glad you figured it out. What was the problem?

Kind regards,

Tim Koschuetzki
Co-Founder Transloadit
@tim_kos

I signed using only the “auth” part of the params; I initially didn’t see in doc that I should include the whole params payload.

Okay could you please point me to the section in the signature auth docs where you would have expected better information? Then I’ll update it.

Thank you.

The docs does say how to do it correct, but I think what misled me was the PHP example (2.7.2 PHP) where $params only includes the ‘auth’ field. Might make it easier to grasp if the example also includes “steps” like the listing in 2.4?

-Harald

Alright, thanks for the suggestion. We made the required changes. :slight_smile: