LTI Launch R180U Student App Report Class - dev1.

Whenever a launch is triggered, the configuration parameters are applied, new nonce and timestamp values are obtained, and a new OAuth signature is calculated. The "Refresh" button does the same, without triggering a launch. Current support is for LTI 1.0/1.1 Adapted from Lance's implementation and customized for testing dashboards

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha1.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64.js"></script>
<h1>
R180U Class Report WORKING COPY  LTI Launch
</h1>
</h1>
<p><em>Remember to click on "Refresh" at the bottom of the form before launching!!</em>

</p>
<h2>LTI configuration parameters</h2>

<form id="ltiConfigurationForm" onsubmit="updateLtiLaunchForm(); return false;">
  <ul>
    <li>
      <label>Launch URL:
        <input id="launchUrl" value="" type="text" />
      </label>
    </li>
    <li>
      <label>View ID:
        <input id="viewId" value="" type="text" />
      </label>
    </li>
    <li>
      <label>Key:
        <input id="key" value="" type="text" size="80" />
      </label>
    </li>
    <li>
      <label>Secret:
        <input id="secret" value="" type="text" size="80" />
      </label>
    </li>
  </ul>
  <button type="submit" style="display: none;"></button>
</form>

<h2>LTI launch parameters</h2>

<form id="ltiLaunchForm" name="ltiLaunchForm" method="POST" action="" onsubmit="updateLtiLaunchForm()">
  <ul>
    <li>
      <label>user_id:
        <input type="text" name="user_id" value="0ae836b9-7fc9-4060-006f-27b2066ac545">
      </label>
    </li>
    <li>
      <label>roles:
        <input type="text" name="roles" value="urn:lti:role:ims/lis/Instructor">
      </label>
    </li>
    <li>
      <label class='sri'>custom_siteId:
        <input type="text" id="custom_siteId" name="custom_siteId" value="mohawk" />
      </label>
    </li>
    <li>
      <label class='sri'>custom_classId:
        <input type="text" id="custom_classId" name="custom_classId" value="CLASS-M-1A" />
      </label>
    </li>
      <li>
      <label class='sri'>custom_first_name:
        <input type="text" id="custom_first_name" name="custom_first_name" value="custom_first_name" />
      </label>
    </li>
      <li>
      <label class='sri'>custom_last_name:
        <input...

CSS

input:read-only {
  background-color: #D6D6D6;
}

em {
  background-color: #FFD666;
}

label.sri {
  background-color: #FFD666;
}

input#launchUrl {
  width: 90%
}

input {
  width: 60%;
}

JavaScript

(function() {
  window.onload = function() {

    // r180u        
    $('#launchUrl').val('https://hmhprod2.intellifylearning.com/ltilaunch/');
    //class view id
    $('#viewId').val('56cbe1ed0cf239a89352f3b7');
    //student view id
    //$('#viewId').val('561dc1310cf29cf10bd93079');
    $('#key').val('DR3O_WSDQgyNXen3au5Qmg');
    $('#secret').val('27aca591-3ced-460e-939f-587384942cfb');
    $('#custom_siteId').val('h900000031');
    $('#custom_classId').val('pjg5omnv7r2hbk29le0p24b6_v8q9qq0');
    //$('#custom_studentId').val('337oro96ar88asu7hpoedqf5_v8q9qq0');


    updateLtiLaunchForm();
  };

  this.updateLtiLaunchForm = function() {
    var launchUrl = $('#launchUrl').val() + $('#viewId').val();
    var encodedSecret = encodeURIComponent($('#secret').val()) + '&';
    var $ltiLaunchForm = $('#ltiLaunchForm');

    $ltiLaunchForm.attr('action', launchUrl);
    $('#oauth_consumer_key').val($('#key').val());
    $('#oauth_timestamp').val(Math.floor(new Date().getTime() / 1000));
    $('#oauth_nonce').val(uniqid('', true));

    var fields = [];
    $('input[type="text"]', $ltiLaunchForm).not('[name="oauth_signature"]').not('[name="custom_param_1_label"]').each(function() {
      var input = $(this);
      fields.push(input.attr('name') + '=' + rawurlencode(input.val()));
    });

    console.log(fields)

    var message = 'POST&' + encodeURIComponent(launchUrl) + '&' + rawurlencode(fields.sort().join('&'));

    console.log(message);

    var oauthSignature = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(message, encodedSecret));
    $('#oauth_signature').val(oauthSignature);
  };

  this.rawurlencode = function(str) {
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
    replace(/\)/g, '%29').replace(/\*/g, '%2A');
  };

  this.uniqid = function(prefix, moreEntropy) {
    prefix = prefix || '';
    moreEntropy = moreEntropy || false;
    var result;

    this.formatSeed...