API Designer throws error with 'Try it'


#1

Hi,

‘Try it’ with Basic Authentication throws such error:

TypeError: Cannot read property 'authenticate' of undefined
at TryIt.execute (http://localhost/scripts/vendor.js:67747:17)
at http://localhost/scripts/vendor.js:18806:21
at callback (http://localhost/scripts/vendor.js:27162:17)
at Scope.$eval (http://localhost/scripts/vendor.js:20714:28)
at Scope.$apply (http://localhost/scripts/vendor.js:20812:23)
at HTMLButtonElement.<anonymous> (http://localhost/scripts/vendor.js:27167:23)
at http://localhost/scripts/vendor.js:10756:10
at forEach (http://localhost/scripts/vendor.js:8228:18)
at HTMLButtonElement.eventHandler (http://localhost/scripts/vendor.js:10755:5)

Version: I grab it from Github yesterday.
Browser: Chrome 39.0.2171.95 m

Any idea?

Thanks


#2

I’m having the same problem and trying to debug it. I’m not a contributor to the software, but I looked at it and it seems that the API Designer is missing a dependency on CryptoJS. It uses the CryptoJS library to base64 encode the Basic Auth credentials.

There is a try/catch around the lines:

try {

  ...

  authStrategy = RAML.Client.AuthStrategies.for(scheme, credentials);
} catch (e) {
  // custom strategies aren't supported yet.
}

The “RAML.Client.AuthStrategies.for(scheme, credentials)” method uses CryptoJS internally. When it fails to load the library, it throws an exception, which is caught in this block. The code continues to the next line where the value of the “authStrategy” variable is null. That causes the error you’re seeing to be thrown to the console.

I’m not sure how the build is supposed to include CryptoJS, so I haven’t been able to fix it yet. Maybe someone else will see this and comment on a solution…


#3

The dependency for Crypto-JS is missing from the “api-designer”. It is defined in the “api-console”, but the dependency is not automatically picked up by the “api-designer”. I fixed it in my local clone by adding the following line to the bower.json file for the api-designer.

    "crypto-js": "https://crypto-js.googlecode.com/files/CryptoJS%20v3.1.2.zip",

And the following lines to the index.html file for the api-designer:

    <!-- build:js({.,.tmp,app}) scripts/vendor.js -->
      ...
    <script src="bower_components/crypto-js/rollups/hmac-sha1.js"></script>
    <script src="bower_components/crypto-js/components/enc-base64.js"></script>
    <!-- endbuild -->

After making these changes and running “grunt server”, the api-designer successfully makes calls using Basic Authentication when clicking “Try It”.