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

Keep getting "No LTIK or IdToken found."message. #55

Closed GreenOn closed 4 years ago

GreenOn commented 4 years ago

Describe the bug This may be perhaps a problem in the LTIKEY setup. I did the setup as described in the tutorial. I am using localhost moodle and when I launch the demo tool, I get this error. {"status":401,"error":"Unauthorized","details":{"message":"No LTIK or IdToken found.","bodyReceived":{}}}

Expected behavior Expecting it to see "Tool works" or some other success message.

Provider logs Copy of the relevant provider logs.

  1. Run code with debug flag: DEBUG=provider:* npm start.
  2. Copy logs relevant to the issue.

Screenshots If applicable, add screenshots to help explain your problem.

Ltijs version

NodeJS version

Additional context Under .env file, I am using LTI_KEY=LTIKEY. Do we need to change this something else? Is this where I need to keep the private key?

Cvmcosta commented 4 years ago

Hello, can you please tell me your provider configurations? (This error usually is caused by the cookie configurations). Also it would help if i could see the logs generated when the error happens (Run code with debug flag: DEBUG=provider:* npm start).

GreenOn commented 4 years ago

Hi, Thanks for your reply. I am actually running the server example on localhost:3000 and the client example on localhost:3001. I was trying with localhost:3001 for the redirect URL and that's when I get the above error. If I use localhost:3000 for the redirect URL in the provider settings, I don't see any error.

Here's my provider config, JIC:



> ltijs-demo@1.0.0 start C:\Users\pramo\ltijs-demo-server
> env DEBUG=provider:* node index.js

  provider:main Attempting to connect to database +0ms
  provider:database Database connected +0ms
  provider:database Database connection open +2ms
  provider:main Ltijs started listening on port:  3000 +2s
  _   _______ _____       _  _____
 | | |__   __|_   _|     | |/ ____|
 | |    | |    | |       | | (___  
 | |    | |    | |   _   | |\___ \ 
 | |____| |   _| |_ | |__| |____) |
 |______|_|  |_____(_)____/|_____/ 

 LTI Provider is listening on port 3000!

 LTI provider config: 
 >App Route: /
 >Initiate Login Route: /login
 >Keyset Route: /keys
 >Session Timeout Route: /sessiontimeout
 >Invalid Token Route: /invalidtoken

Starting in Dev Mode, state validation and session cookies will not be required. THIS SHOULD NOT BE USED IN A PRODUCTION ENVIRONMENT!
  provider:main Platform already registered +404ms
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtbnGXCq/7seLLuCA8lvm
+zmN2/AB79pLEwbMwiReBhMHL6rLiHyYLYLjAswtB7HSSlJ8XS6CPk6sEcrgy1pA
VyZmnzXqBNsEKSCXo5EuhA0d3arVqTJrKkeS2gbTjtW7BxuhGR8CzyRYT2ZM9a6A
B/7XGEnVgZbkN2siPE/7vVjpCmrZ39JV6Offk2rKBp58NhVxIQaWy/VwD1nBr01j
anVW/ILCvOeFjOEh5DpRv+CGMAWatQRHCASFv/fprSGCStzDFcWKYC20uISUoS0C
pZlbU6O7/+uENp7JUUTKna9D8d5AGgffIsAmpOHJ3jT3uWjXOccEZ55zowXb1Njt
pdnokIbI9yMVcj0bPEVI/HTpCQzIzI/snBAabygulJFrdTMgJoJxfOTMwtfhwJnu
IyL0Gb6HHem6FcFv0lTNiTvbUmcUcPBjK/inllugJd0Kd1XF4bt90qzF967wzCaC
7JnpYbm/NW3CFZd4DKZepUhPP8IwiBOK5IfpmZBrD5PlWS8m/2C5Pejl5E5hS0Kl
VJMsQZcei0V2//v99Z9gH2rV335WaaJt64TdJXmnnoFdXQ4sbb7NyCHjCUw/E2WA
XhIbzSj983KigXxweBNx2xIpwb1LbO5yh5Y0g0gL4fZugbzz3xOtrnDZ2Y49MiDC
EBf0/ntavu1eJFgHkgW9jy8CAwEAAQ==
-----END PUBLIC KEY-----```
Cvmcosta commented 4 years ago

Wait so you are no longer seeing any errors? If you're still having issues, can you show me the logs at the exact time of the error, they should display relevant information.

GreenOn commented 4 years ago

Here's the log:

-----END PUBLIC KEY-----

Deployed!
  provider:main Receiving request at path: /login +20s
  provider:main Receiving a login request from: http://localhost +3ms
  provider:main Redirecting to platform authentication endpoint +181ms
  provider:main Target Link URI:  http://localhost:3000 +112ms
  provider:main Login request:  +4ms
  provider:main {
  provider:main   response_type: 'id_token',
  provider:main   response_mode: 'form_post',
  provider:main   id_token_signed_response_alg: 'RS256',
  provider:main   scope: 'openid',
  provider:main   client_id: 'vnJik1AZWVdIs8A',
  provider:main   redirect_uri: 'http://localhost:3000',
  provider:main   login_hint: ['2',]
  provider:main   nonce: '53izruqm1zthk5dssib6d7ep6',
  provider:main   prompt: 'none',
  provider:main   state: '9bb830055654094c8218e343fed6fe3253af6c7ee963b40d86',
  provider:main   lti_message_hint: '2',
  provider:main   lti_deployment_id: '1'
  provider:main } +2ms
  provider:main Receiving request at path: / +89ms
  provider:main Path does not match reserved endpoints +4ms
  provider:main Cookies received:  +1ms
  provider:main [Object: null prototype] {
  provider:main   'ltiaHR0cDovL2xvY2FsaG9zdHZuSmlrMUFaV1ZkSXM4QTE%3D': '2',
  provider:main   state9bb830055654094c8218e343fed6fe3253af6c7ee963b40d86: 'http://localhost'
  provider:main } +1ms
  provider:main Deleting state cookie and Database entry +2ms
  provider:main Accessing as whitelisted route +66ms
  provider:main Receiving request at path: /main +71ms
  provider:main Path does not match reserved endpoints +1ms
  provider:main Cookies received:  +0ms
  provider:main [Object: null prototype] {
  provider:main   'ltiaHR0cDovL2xvY2FsaG9zdHZuSmlrMUFaV1ZkSXM4QTE%3D': '2'
  provider:main } +299ms
  provider:main No LTIK found +118ms
  provider:main Request body:  {} +1ms
  provider:main Passing request to invalid token handler +197ms
  provider:main Receiving request at path: /invalidtoken +134ms

Moodle Settings: https://prnt.sc/ux9x92

Cvmcosta commented 4 years ago

According to the print you posted, your redirection URL is incorrect, it should be the same as the Tool URL field.

GreenOn commented 4 years ago

Thanks. That works. I am getting a hang of this. I am following your medium article on this and trying out a few things. The grading service almost worked, but I got the "Incorrect score received" error. The log is shown below. Could you take a look and see if there is an issue with the grade object?

 provider:gradeService Target platform: http://localhost +0ms
  provider:gradeService Attempting to retrieve platform access_token for [http://localhost] +202ms
  provider:platform Access_token found +0ms
  provider:gradeService Access_token retrieved for [http://localhost] +87ms
  provider:gradeService Target platform: http://localhost +3ms
  provider:gradeService Sending score to: http://localhost/mod/lti/services.php/2/lineitems/2/lineitem/scores?type_id=1 +204ms
  provider:gradeService {
  provider:gradeService   scoreGiven: 70,
  provider:gradeService   comment: 'This is exceptional work.',
  provider:gradeService   activityProgress: 'Completed',
  provider:gradeService   gradingProgress: 'FullyGraded',
  provider:gradeService   userId: '2',
  provider:gradeService   timestamp: '2020-10-12T00:41:31.205Z',
  provider:gradeService   scoreMaximum: 100
  provider:gradeService } +1ms
  provider:gradeService HTTPError: Response code 400 (Incorrect score received{"scoreGiven":70,"comment":"This is exceptional work.","activityProgress":"Completed","gradingProgress":"FullyGraded","userId":"2","timestamp":"2020-10-12T00:41:31.205Z","scoreMaximum":100})
  provider:gradeService     at Request.<anonymous> (C:\Users\pramo\ltijs-demo-server\node_modules\got\dist\source\as-promise\index.js:117:42)
  provider:gradeService     at processTicksAndRejections (internal/process/task_queues.js:97:5) +380ms
Cvmcosta commented 4 years ago

I don't actually recommend following that tutorial since i'ts quite outdated and based on an older version of Ltijs. Im working on updating it.

Regarding your issue, you should check if the current user is enrolled in the course, as an admin you can always access the course but you're not necessarily enrolled in it.

GreenOn commented 4 years ago

That makes sense! Thanks for your work.