Last active
August 13, 2024 11:51
-
-
Save willwm/f313c9e998d237c99406a657482013bf to your computer and use it in GitHub Desktop.
lcom-techblog: LTI JavaScript Example (https://medium.com/lcom-techblog/simple-lti-tool-consumer-in-html-and-javascript-72ca153d7a83)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var oauth = require('oauth-sign'); | |
var action = 'https://lti.tools/saltire/tp'; | |
var method = 'POST'; | |
var timestamp = Math.round(Date.now() / 1000); | |
var params = { | |
// LTI Required Parameters | |
lti_message_type: 'basic-lti-launch-request', | |
lti_version: 'LTI-1p0', | |
resource_link_id: 'resourceLinkId', | |
// OAuth 1.0a Required Parameters | |
oauth_consumer_key: 'jisc.ac.uk', | |
oauth_nonce: btoa(timestamp), | |
oauth_signature_method: 'HMAC-SHA1', | |
oauth_timestamp: timestamp, | |
oauth_version: '1.0' | |
}; | |
var signature = oauth.hmacsign(method, action, params, 'secret'); | |
params.oauth_signature = signature; | |
var form = document.querySelector("#ltiForm"); | |
form.action = action; | |
form.method = method; | |
for (var name in params) { | |
var node = document.createElement("input"); | |
node.name = name; | |
node.type = 'hidden'; | |
node.value = params[name]; | |
form.appendChild(node); | |
} | |
var output = document.querySelector("code"); | |
output.textContent = JSON.stringify(params, null, 2); | |
console.log(form); | |
var meta = document.querySelector("body > script"); | |
console.log(meta); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's useful.