Hi Peter et al.,
First of all, thank you so much for all your great replies on this forum, they have helped me immensely! I'm a bit of beginner when it comes to coding, etc. I have a node server up and running using express, and a mongo database for my client secret and id.
I'm building an app that allows students to do music exercises, then posts their scores back to Canvas. It works fine with my self-generated API token, but I've stumbled quite a bit with the OAuth flow. I finally have my local instance of Canvas accepting my app's launch via OAuth. I used the library you posted above ims-lti to verify the launch. The library also works to passback a test grade on launch (which is useless since the user hasn't done anything yet). But when it comes to actually persisting the provider instance I run into problems.
My app loads a template with the exercise and the client-side javascript then sends the submission info back to my server via a post request. I need the provider instance to then send the grade info to Canvas from my node server. The problem is that the provider instance is gone, as is all the important launch data. I can save the launch data in a server-side session, I even tried storing the provider instance there, but I think the functionality of the provider instance is lost once it has been moved to req.session (maybe it's all just JSON by then?). provider.send_replace_result returns undefined if I try to use it...is there a suggested and safe way to save that provider instance while the server waits for the student to finish their assignment?
Thanks in advance!
Scott
UPDATE: I think I got it! I just instantiated a new lti.OutcomeService with the below options
const options = {
consumer_key: 1,
consumer_secret: req.session.provider.consumer_secret, /// LOOKUP FROM DATABASE???
service_url: req.session.provider.outcome_service.service_url,
source_did: req.session.provider.body.lis_result_sourcedid,
result_data_types: ['text']
};
const outcome = new lti.OutcomeService(options);
console.log(outcome.send_read_result);
const score = 95/100;
const message = `This Basics of Music assignment was completed with a score of ${score * 100}%.`;
outcome.send_read_result((err, previousScore) => {
if (err) {
console.log(err);
} else {
if (previousScore < score) {
outcome.send_replace_result_with_text(score, message, (err, result) => {
if (err) {
console.log(err);
} else {
console.log('sent grade with message');
}
})
}
}
})