Cvmcosta / ltijs

Turn your application into a fully integratable LTI 1.3 tool provider.
https://cvmcosta.github.io/ltijs/
Apache License 2.0
299 stars 67 forks source link

Cannot read property 'lineitem' of null error when using lti.Grade.getLineItems(idtoken, { resourceLinkId: true }) #96

Closed vandergav closed 3 years ago

vandergav commented 3 years ago

Hi Carlos, sorry for bringing up another issue again so soon but I am having some difficulties with the "Grading route" (and also the "Names and Roles" route but that can be for another time) in routes.js of the ltijs-demo-server.

routes.js: image Here are the logs: image From the logs, I can see that the "endpoint" value is null. Am I missing something here?

I then tweaked the code to bypass the null value by adding the line let lineItemId = (idtoken.platformContext.endpoint) ? idtoken.platformContext.endpoint.lineitem : null but then hit an error at the lti.Grade.getLineItems(idtoken, { resourceLinkId: true }) line: image

Thanks for your help in advance Carlos!

Cvmcosta commented 3 years ago

Hello! This is a permissions issue. You need to enable the Grades and Names and Roles service when registering the Tool on Moodle. If you don't give the tool the correct access, the ID Token will not contain the endpoint field.

vandergav commented 3 years ago

Thanks Carlos for the speedy reply! Following your instructions, I created a new tool and enabled the Grades and Names and Roles service on it and now the endpoint is showing and I am able to get the lineItemId, however there is still an issue with this line const response = await lti.Grade.getLineItems(idtoken, { resourceLinkId: true }), I am getting a Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt error as seen this the console logs: image image Some extra info: I had deleted the platform before registering a new Platform instance

Cvmcosta commented 3 years ago

Ah, i know what this is. This issue is happening because you switched the LTI_KEY after registering Platforms. Basically the Platform is trying to get the Keyset (Collection of every Public Key for every Platform registered), and LTIJS is unable to decrypt some of them due to the LTI_KEY used to encrypt not being the same one being used to decrypt.

This is a hard to fix issue unless you know the client ID of every Platform you registered with the old keys. My suggestion would actually be to delete the platforms, publickey and privatekey tables from the Database manually and then create a new one. Alternatively you could just use a new database and it would have the same affect.

vandergav commented 3 years ago

Thanks Carlos it works now! I did what you said about deleting the old data from the platforms, publickey and privatekey tables and it works now. Luckily for me, it was quite easy to identify the old data because the table headers were clear. Again, thank you loads for your very speedy assistance.

Just also want to add: image I have tested Ltijs Sequelize Database Plugin with MariaDB and found it to be working. FYI.

Cvmcosta commented 3 years ago

Oh, great! Thanks for letting me know! I will update the documentation soon.