1

I am trying to implement Adobe's Creative SDK into my Ruby on Rails app.

https://creativesdk.adobe.com/docs/web/#/articles/highresolution/index.html

I have the required access to the hi-res API.

The examples they have are for PHP and Node.js, and I am trying to write a Ruby on Rails version based on the PHP. I have it all setup, in that it's properly calling the "authenticationURL" but I'm getting an "Invalid authenticationURL response. Please check the formatting the response."

I'm new to programming at this level and basically tried to figure this out by referencing a few questions on PHP & Ruby here as well sites like http://www.phptoruby.com/.

Here is the PHP:

<!-- /getAuth -->

<?php
$apiKey = "apikey";
$apiSecret = "apisecret";
$salt = rand(0,1000);
$time = time();
$sig = sha1($apiKey . $apiSecret . $time . $salt);

$authObj = array(
    "apiKey" => $apiKey,
    "salt" => $salt,
    "timestamp" => $time,
    "encryptionMethod" => 'sha1',
    "signature" => $sig
);

echo json_encode($authObj);

?>

Here is what I have at the moment (with my apikey and apisecret entered correctly):

require 'time'
require 'json'
require 'digest/sha1'

def get_auth
 apiKey = 'apikey'
 apiSecret = 'apisecret'
 salt = "#{0 + rand(1000)}"
 time = "#{Time.now.to_i}"
 sig = Digest::SHA1.hexdigest('apiKey' + 'apiSecret' + 'time' + 'salt')


 authObj = { :apiKey => 'apiKey',
                 :salt => 'salt',
                 :timestamp => 'time',
                 :encryptionMethod => 'sha1',
                 :signature => 'sig' }

 print 'authObj'.to_json
 render :fxb
end

I'm not sure if using print is correct here? Or if my problem is a syntax issue... Or something else entirely.

mdh1
  • 11
  • 1
  • Is your issue resolved ? I am also getting the same error as "Invalid authenticationURL response. Please check the formatting the response.". I am using c# and I have access to high res API too. Raised a complaint to adobe but no one responding. Auth object is gettin created correctly in C# and I have compared the json with creative cloud documentation testing url for auth object but still not working http://jsbin.com/xoxaqoropu/ – adang Jan 13 '17 at 02:43
  • Ok, I have solved issue for me. After debugging the minified aviary js I found that my getAuth function was returning a correct json (auth) but I have to add the response header so that the aviary can parse the auth json object into signature, timestamp. SO I have to add below in getAuth method before returning json. Without it aviary was reading the auth json as string and not object and it was failing to parse it. Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; – adang Jan 13 '17 at 03:57

4 Answers4

1

Try changing

 sig = Digest::SHA1.hexdigest('apiKey' + 'apiSecret' + 'time' + 'salt')

to

 sig = Digest::SHA1.hexdigest(apiKey + apiSecret + time + salt)

With the single quotes, it is taking apiKey string itself as the value to be hashed, and not its value.

Also, the following needs to be changed as well to remove the single quotes:

authObj = { :apiKey => 'apiKey',
                 :salt => 'salt',
                 :timestamp => 'time',
                 :encryptionMethod => 'sha1',
                 :signature => 'sig' }

 print 'authObj'.to_json

to

authObj = { :apiKey => apiKey,
                 :salt => salt,
                 :timestamp => time,
                 :encryptionMethod => sha1,
                 :signature => sig }

 print authObj.to_json
Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
  • Awesome. No longer getting that error but now I'm getting `NameError (undefined local variable or method 'sha1' for #): app/controllers/uploads_controller.rb:28:in 'get_auth'` – mdh1 Jul 14 '16 at 15:09
  • I changed `:encryptionMethod => sha1` to `:encryptionMethod => 'sha1'` and I am no longer getting the `NameError` in the logs, and in fact, everything seems ok in the logs - salt, timestamp, signature, and encryptionMethod (as 'sha1') are all there but now I'm getting the initial "Invalid authenticationURL response" javascript error again. – mdh1 Jul 14 '16 at 16:10
0

add this as a controller action:

  def auth_aviary
    timestamp = Time.now.to_i.to_s
    salt = rand(1000).to_s
    sig = Digest::SHA1.hexdigest(
            Conf.aviary_api_key + 
            Conf.aviary_api_secret + 
            timestamp + 
            salt
          )
    render json: {
      "apiKey" => Conf.aviary_api_key,
      "salt" => salt,
      "timestamp" => timestamp,
      "encryptionMethod" => 'sha1',
      "signature" => sig
    }
  end
Tom Lobato
  • 136
  • 2
  • 4
0

Responding to an old post for those who are still facing issue. The solution might work (atleast for asp.net). I was getting same error and it was resolved once I have set the response content type as "application/json; charset=utf-8". Without it aviary was reading the auth json as string and not object and it was failing to parse it into timestamp, signature etc

Response.ContentType = "application/json; charset=utf-8";

Hope it will help.

adang
  • 547
  • 4
  • 14
0

Yes in php i set header and all work fine.

header('Content-Type: application/json');