Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/members and /grade endpoints are not working. They are throwing 500 error. #193

Open
RajendraChowdary21 opened this issue Jul 6, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@RajendraChowdary21
Copy link

500 error

Our tool has been added to canvas and while trying to hit the "names and roles service" and "grade service" I'm getting 500 error.

In /members endpoint I have added consoles. first console is happening and I'm getting the token. second console is not happening and Its directly going to catch block and error is being consoled. The error that is being consoled is error console --> Cannot read property 'context_memberships_url' of undefined

router.get('/members', async (req, res) => {
  try {
    console.log("hitting members endpoint :::::", res.locals.token)
    const result = await lti.NamesAndRoles.getMembers(res.locals.token)
    console.log("result :::::", result)
    if (result) return res.send(result.members)
    return res.sendStatus(500)
  } catch (err) {
    console.log("error in catch block :::::", err.message)
    return res.status(500).send({message:err.message, response: res.locals})
  }
})

And total response that is coming to this endpoint is below

{
    "context": {
        "contextId": "https%3A%2F%2Fcanvas.instructure.com240060000000000125206%3A2f473bfcbb3505b3b4b38f70d7b83013247d5f162f473bfcbb3505b3b4b38f70d7b83013247d5f16_2f473bfcbb3505b3b4b38f70d7b83013247d5f16",
        "user": "b7ad0c0a-8659-4311-bc4e-e752b64da51c",
        "roles": [
            "http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator",
            "http://purl.imsglobal.org/vocab/lis/v2/institution/person#Instructor",
            "http://purl.imsglobal.org/vocab/lis/v2/system/person#User"
        ],
        "path": "/",
        "targetLinkUri": "https://3f75-2401-4900-62e1-9e93-80e3-5dbf-e6ef-398d.ngrok-free.app",
        "context": {
            "id": "2f473bfcbb3505b3b4b38f70d7b83013247d5f16",
            "title": "Aauti",
            "type": [
                "Account"
            ],
            "validation_context": null
        },
        "resource": {
            "id": "2f473bfcbb3505b3b4b38f70d7b83013247d5f16",
            "description": null,
            "title": "Aauti",
            "validation_context": null
        },
        "launchPresentation": {
            "document_target": "iframe",
            "return_url": "https://auti.instructure.com/accounts/1/external_content/success/external_tool_redirect",
            "locale": "en",
            "validation_context": null,
            "height": 400,
            "width": 800
        },
        "messageType": "LtiResourceLinkRequest",
        "version": "1.3.0",
        "lis": {
            "person_sourcedid": null,
            "course_offering_sourcedid": "$CourseSection.sourcedId",
            "validation_context": null
        },
        "createdAt": "2023-07-06T06:27:19.208Z"
    },
    "token": {
        "iss": "https://canvas.instructure.com",
        "user": "b7ad0c0a-8659-4311-bc4e-e752b64da51c",
        "userInfo": {
            "given_name": "Rajendra",
            "family_name": "Gutha",
            "name": "Rajendra Gutha",
            "email": "[email protected]"
        },
        "platformInfo": {
            "guid": "JI5f2mIn3TGUy4zaf3Y84XqmJqjMX8Ft9gX8UO7h",
            "name": "Aauti",
            "version": "cloud",
            "product_family_code": "canvas",
            "validation_context": null
        },
        "clientId": "240060000000000125",
        "platformId": "e4d88b9f6b6061a9198cbeb9ce0e0d18",
        "deploymentId": "206:2f473bfcbb3505b3b4b38f70d7b83013247d5f16",
        "createdAt": "2023-07-06T06:27:19.196Z",
        "platformContext": {
            "contextId": "https%3A%2F%2Fcanvas.instructure.com240060000000000125206%3A2f473bfcbb3505b3b4b38f70d7b83013247d5f162f473bfcbb3505b3b4b38f70d7b83013247d5f16_2f473bfcbb3505b3b4b38f70d7b83013247d5f16",
            "user": "b7ad0c0a-8659-4311-bc4e-e752b64da51c",
            "roles": [
                "http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator",
                "http://purl.imsglobal.org/vocab/lis/v2/institution/person#Instructor",
                "http://purl.imsglobal.org/vocab/lis/v2/system/person#User"
            ],
            "path": "/",
            "targetLinkUri": "https://3f75-2401-4900-62e1-9e93-80e3-5dbf-e6ef-398d.ngrok-free.app",
            "context": {
                "id": "2f473bfcbb3505b3b4b38f70d7b83013247d5f16",
                "title": "Aauti",
                "type": [
                    "Account"
                ],
                "validation_context": null
            },
            "resource": {
                "id": "2f473bfcbb3505b3b4b38f70d7b83013247d5f16",
                "description": null,
                "title": "Aauti",
                "validation_context": null
            },
            "launchPresentation": {
                "document_target": "iframe",
                "return_url": "https://auti.instructure.com/accounts/1/external_content/success/external_tool_redirect",
                "locale": "en",
                "validation_context": null,
                "height": 400,
                "width": 800
            },
            "messageType": "LtiResourceLinkRequest",
            "version": "1.3.0",
            "lis": {
                "person_sourcedid": null,
                "course_offering_sourcedid": "$CourseSection.sourcedId",
                "validation_context": null
            },
            "createdAt": "2023-07-06T06:27:19.208Z"
        }
    },
    "ltik": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwbGF0Zm9ybVVybCI6Imh0dHBzOi8vY2FudmFzLmluc3RydWN0dXJlLmNvbSIsImNsaWVudElkIjoiMjQwMDYwMDAwMDAwMDAwMTI1IiwiZGVwbG95bWVudElkIjoiMjA2OjJmNDczYmZjYmIzNTA1YjNiNGIzOGY3MGQ3YjgzMDEzMjQ3ZDVmMTYiLCJwbGF0Zm9ybUNvZGUiOiJsdGlhSFIwY0hNNkx5OWpZVzUyWVhNdWFXNXpkSEoxWTNSMWNtVXVZMjl0TWpRd01EWXdNREF3TURBd01EQXdNVEkxTWpBMk9qSm1ORGN6WW1aalltSXpOVEExWWpOaU5HSXpPR1kzTUdRM1lqZ3pNREV6TWpRM1pEVm1NVFklM0QiLCJjb250ZXh0SWQiOiJodHRwcyUzQSUyRiUyRmNhbnZhcy5pbnN0cnVjdHVyZS5jb20yNDAwNjAwMDAwMDAwMDAxMjUyMDYlM0EyZjQ3M2JmY2JiMzUwNWIzYjRiMzhmNzBkN2I4MzAxMzI0N2Q1ZjE2MmY0NzNiZmNiYjM1MDViM2I0YjM4ZjcwZDdiODMwMTMyNDdkNWYxNl8yZjQ3M2JmY2JiMzUwNWIzYjRiMzhmNzBkN2I4MzAxMzI0N2Q1ZjE2IiwidXNlciI6ImI3YWQwYzBhLTg2NTktNDMxMS1iYzRlLWU3NTJiNjRkYTUxYyIsInMiOiJkY2M3NzI3MDMzNzVjY2Y1MzRjODVmZjY2YWExNWMwNDRmMDZmYTQ4MjAxNGU3NTg4NCIsImlhdCI6MTY4ODYyNDgzOX0.Hr5FkrNGocr32cnlHT_dLdx8UV3FlD5nGdCKwuWwSJ8"
}

Expected behavior

The response that is expected as shown here

{
  "id" : "https://lms.example.com/sections/2923/memberships",
  "context": {
    "id": "2923-abc",
    "label": "CPS 435",
    "title": "CPS 435 Learning Analytics",
  },
  "members" : [
    {
      "status" : "Active",
      "name": "Jane Q. Public",
      "picture" : "https://platform.example.edu/jane.jpg",
      "given_name" : "Jane",
      "family_name" : "Doe",
      "middle_name" : "Marie",
      "email": "[email protected]",
      "user_id" : "0ae836b9-7fc9-4060-006f-27b2066ac545",
      "lis_person_sourcedid": "59254-6782-12ab",
      "roles": [
        "http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor"
      ]
    }
  ]
}

Provider logs

provider:main Platform already registered +57ms
provider:main Receiving request at path: /members +48s
provider:main Path does not match reserved endpoints +2ms
provider:main Cookies received: +2ms
provider:main [Object: null prototype] {} +1ms
provider:main Ltik found +2ms
provider:main Ltik successfully verified +29ms
provider:main Attempting to retrieve matching session cookie +1ms
provider:main Dev Mode enabled: Missing session cookies will be ignored +1ms
provider:auth Valid session found +0ms
provider:main Passing request to next handler +27ms
provider:namesAndRolesService Attempting to retrieve memberships +0ms
provider:namesAndRolesService Target platform: https://canvas.instructure.com +1ms
provider:namesAndRolesService Attempting to retrieve platform access_token for [https://canvas.instructure.com] +28ms
provider:platform Access_token found +0ms
provider:namesAndRolesService Access_token retrieved for [https://canvas.instructure.com] +89ms
error console --> Cannot read property 'context_memberships_url' of undefined
provider:main Receiving request at path: /members +967ms
provider:main Path does not match reserved endpoints +1ms
provider:main Cookies received: +1ms
provider:main [Object: null prototype] {} +0ms
provider:main Ltik found +1ms
provider:main Ltik successfully verified +5ms
provider:main Attempting to retrieve matching session cookie +2ms
provider:main Dev Mode enabled: Missing session cookies will be ignored +0ms
provider:auth Valid session found +1s
provider:main Passing request to next handler +14ms
provider:namesAndRolesService Attempting to retrieve memberships +871ms
provider:namesAndRolesService Target platform: https://canvas.instructure.com +1ms
provider:namesAndRolesService Attempting to retrieve platform access_token for [https://canvas.instructure.com] +15ms
provider:platform Access_token found +900ms
provider:namesAndRolesService Access_token retrieved for [https://canvas.instructure.com] +11ms
error console --> Cannot read property 'context_memberships_url' of undefined

Screenshots

image

image

image

Ltijs version

  • Version [5.9.1]

NodeJS version

  • Version [14]

Platform used

  • [Canvas]
@RajendraChowdary21 RajendraChowdary21 added the bug Something isn't working label Jul 6, 2023
@Liziqiuqiu
Copy link

@RajendraChowdary21 Hello, have you found any solutions to this issue or discovered any other workarounds? I'm experiencing the same error.

@Cvmcosta
Copy link
Owner

Cvmcosta commented Dec 5, 2023

@RajendraChowdary21 @Liziqiuqiu

Hello! Nice to meet you!

The error in question is likely caused by lack of permissions when setting up the tool in the LMS. Which LMS are you using? Did you enable these services when setting up the tool?

@Liziqiuqiu
Copy link

Liziqiuqiu commented Dec 5, 2023

Hi Carlos,
Thank you so much for your response. I am using the Canvas test server hosted by Instructure. When I created the developer key, I enabled the following LTI Advantage services. Are there any other settings that should be enabled for the grade endpoint to function correctly? Once again, thank you so much for your assistance.
LTI advantage services

Not sure if it has something to do with the setup and platform registration

lti.setup('Thsisnenkskejeekw',
  {
    url:'mongodb://localhost/ltidb2?authSource=admin', // connection to mongodb
  }, 
  {
  staticPath: path.join(__dirname, './public'), 
  cookies: {
    secure: true, 
    sameSite: 'None' 
  },
  devMode: false 
})

//...

//platform registration
  await lti.registerPlatform({
    url: 'https://canvas.test.instructure.com', 
    name: 'Canvas',
    clientId: '93420000000000280',
    authenticationEndpoint: 'https://sso.test.canvaslms.com/api/lti/authorize_redirect',
    accesstokenEndpoint: 'https://sso.test.canvaslms.com/login/oauth2/token',
    authConfig: { method: 'JWK_SET', key: 'https://sso.test.canvaslms.com/api/lti/security/jwks' }
  })


@Liziqiuqiu
Copy link

Does this have something to do with the scope? It appears that the scope is inconsistent. For example, in the token, it shows the following scopes:
endpoint: { scope: [ 'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem', 'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly', 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly', 'https://purl.imsglobal.org/spec/lti-ags/scope/score', 'https://canvas.instructure.com/lti-ags/progress/scope/show' ],

However, in the provider log, only the 'lineitem.readonly' scope is used.

 provider:gradeService Target platform: https://canvas.test.instructure.com +4m
  provider:gradeService Attempting to retrieve platform access_token for [https://canvas.test.instructure.com] +4ms
  provider:platform Valid access_token for https://canvas.test.instructure.com not found +4m
  provider:platform Attempting to generate new access_token for https://canvas.test.instructure.com +1ms
  **provider:platform With scopes: https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly +0ms**
  provider:auth Awaiting return from the platform +17s

@Cvmcosta
Copy link
Owner

Hello @Liziqiuqiu, you error log looks different than the one presented by the first person to post this issue. Do you have any logs beyond these ones? Is the suer you are sending grades to a student in the course? It needs to be for the grade to be successfully sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants