Discuss Scratch

mrpotes
New Scratcher
2 posts

Extension not loading properly

Hi all,

I'm having problems getting any blocks to appear after clicking the Load Experimental Button, and pasting my Extension URL in the middle panel. My extension is at http://mrpotes.github.io/scratchx-openam/openam-extension.js

If anyone can point out what I'm doing wrong, I'd be very grateful!

Cheers
James
Mrcomputer1
Scratcher
500+ posts

Extension not loading properly

The thing that is making your extension fail to load is on line 94
Line 94 is
    });
should be
    };

Fixed extension code
(function(ext) {
  var authObject = null,
      ssoTokenId = null,
      userDetails = null,
      inputNeeded = false,
      complete = false,
      authenticateResponse = function(response) {
        if (response.tokenId) {
          ssoTokenId = response.tokenId;
          complete = true;
        } else {
          authObject = response;
          inputNeeded = true;
        }
      };
  // Cleanup function when the extension is unloaded
  ext._shutdown = function() {};
  // Status reporting code
  // Use this to report missing hardware, plugin or unsupported browser
  ext._getStatus = function() {
    return {status: 2, msg: 'Ready'};
  };
  ext.startAuth = function(amUrl) {
    baseAmUrl = amUrl;
    authObject = {};
    ext.authenticate();
  };
  ext.authenticate = function() {
    // Make an AJAX call to the OpenAM authenticate endpoint
    $.ajax({
      url: baseAmUrl + '/json/authenticate',
      dataType: 'jsonp',
      type: 'POST',
      data: JSON.stringify(authObject),
      mimeType: 'application/json',
      success: authenticateResponse
    });
  };
  ext.inputNeeded = function() {
    if (inputNeeded === true) {
      inputNeeded = false;
      return true;
    }
    return false;
  };
  ext.getNumberInputs = function() {
    return authObject.callbacks.length;
  };
  ext.getInput = function(i) {
    return 'Please enter your ' + authObject.callbacks[i].output;
  };
  ext.setInput = function(i, value) {
    authObject.callbacks[i].input.value = value;
  };
  ext.complete = function() {
    if (complete === true) {
      complete = false;
      return true;
    }
    return false;
  };
  ext.getDetails = function(attribute, callback) {
    if (userDetails) {
      callback(userDetails[attribute]);
      return;
    }
    $.ajax({
      url: amUrl + '/json/users?_action=idFromSession',
      headers: { iPlanetDirectoryPro: ssoTokenId },
      data: '{}',
      dataType: 'jsonp',
      type: 'POST',
      mimeType: 'application/json'
    }).then(null, function(result) {
      return $.ajax({
        url: amUrl + '/json/users/' + result.id,
        headers: { iPlanetDirectoryPro: ssoTokenId },
        dataType: 'jsonp',
        type: 'GET'
      });
    }).done(function(result) {
      userDetails = result;
      callback(userDetails[attribute]);
    }); //LINE CHANGED FROM }; TO });
  };
  // Block and block menu descriptions
  var descriptor = {
    blocks: [
      ['', 'start authentication from %s', 'startAuth', 'http://local.example.com:8080/openam'],
      ['h', 'authentication input needed', 'inputNeeded'],
      ['r', 'get authentication input count', 'getNumberInputs'],
      ['r', 'get authentication input %n', 'getInput', ''],
      ['', 'set authentication input %n to %s', 'setInput', '', ''],
      ['', 'send authentication details', 'authenticate'],
      ['h', 'authentication complete', 'complete'],
      ['R', 'get user detail called %s', 'getDetails', 'cn'],
    ]
  };
  // Register the extension
  ScratchExtensions.register('OpenAM Extension', descriptor, ext);
})({});

Last edited by Mrcomputer1 (July 30, 2015 11:38:40)

mrpotes
New Scratcher
2 posts

Extension not loading properly

Argh! Thanks

Powered by DjangoBB