Cvmcosta / ltijs

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

Error retrieving NameAndRoles #64

Closed nmtoan251998 closed 3 years ago

nmtoan251998 commented 3 years ago

Describe the bug I'm trying to retrieve data in class NamesAndRoles - function getMembers and get the error HTTPError: Response code 500 (Internal Server Error)

I have logged the data platform from this line

// NameAndRoles.js
async getMembers(idtoken, options) {
...
const platform = await (0, _classPrivateFieldGet2.default)(this, _getPlatform).call(this, idtoken.iss, idtoken.clientId, (0, _classPrivateFieldGet2.default)(this, _ENCRYPTIONKEY), (0, _classPrivateFieldGet2.default)(this, _Database));

console.log({ platform }); // { platform: Platform: {} }
...
}

const options = { limit: 1 };
const idtoken = {
    iss: 'https://canvas.instructure.com',
    user: 'a684e22b-9978-4cef-98d8-98ee5f4cfd6c',
    platformInfo: {
        guid: 'OJwJhR6cNZVC9aiyUh8DLT9onnyVif2hOWpa5490:canvas-lms',
        name: 'Root account',
        version: 'cloud',
        product_family_code: 'canvas',
        validation_context: null
    },
    clientId: '10000000000004',
    platformId: '8421b0dc94540ac04bdf13cc5f7f4460',
    deploymentId: '24:e7484a3d7fa6e228f44fc0fd50c318add6f918bf',
    createdAt: '2020-11-13T03:43:04.941Z',
    platformContext: {
        roles: [Array],
        contextId: 'https%3A%2F%2Fcanvas.instructure.com1000000000000424%3Ae7484a3d7fa6e228f44fc0fd50c318add6f918bfe7484a3d7fa6e228f44fc0fd50c318add6f918bf_e7484a3d7fa6e228f44fc0fd50c318add6f918bf',
        path: '/',
        user: 'a684e22b-9978-4cef-98d8-98ee5f4cfd6c',
        targetLinkUri: 'https://localhost:3003',
        context: [Object],
        resource: [Object],
        launchPresentation: [Object],
        messageType: 'LtiResourceLinkRequest',
        version: '1.3.0',
        endpoint: [Object],
        namesRoles: [Object],
        createdAt: '2020-11-13T03:43:04.957Z'
    }
}

NameAndRolesConsumer

// NameAndRolesConsumer.js
async function caller() {
    const token = res.locals.token;
    const result = await lti.NamesAndRoles.getMembers(token, { limit: 1 });
}

Expected behavior The expected response will be look like the provided response in the documentation in namesandroles

{
  "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": "jane@platform.example.edu",
      "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 Copy of the relevant provider logs.

  1. Run code with debug flag: DEBUG=provider:* npm start.
  2. Copy logs relevant to the issue.
    2020-11-13T11:32:26.163Z provider:namesAndRolesService HTTPError: Response code 500 (Internal Server Error)
    at Request.<anonymous> (/app/node_modules/got/dist/source/as-promise/index.js:117:42)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

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

Ltijs version

NodeJS version

Platform used

Additional context LTI configuration function

// Setup function
const setup = async () => {
    await lti.deploy({ port: vars.PORT }); // vars.PORT = 3000

    const ltiPlatConfig = {
        url: 'https://canvas.instructure.com',
        name: 'dvseok',
        clientId: '10000000000004',
        authenticationEndpoint: 'http://dvseok.shop/api/lti/authorize_redirect',
        accesstokenEndpoint: 'http://dvseok.shop/login/oauth2/token',
        authConfig: {
            method: 'JWK_SET',
            key: 'http://dvseok.shop/api/lti/security/jwks',
        },
    };

    const platform = await lti.registerPlatform(ltiPlatConfig);
    console.log(platform); // { Platform: {}}
};
nmtoan251998 commented 3 years ago

Additionally, these are my token and context values from res.locals respectively

{
        "token": {
            "iss": "https://canvas.instructure.com",
            "user": "a684e22b-9978-4cef-98d8-98ee5f4cfd6c",
            "platformInfo": {
                "guid": "OJwJhR6cNZVC9aiyUh8DLT9onnyVif2hOWpa5490:canvas-lms",
                "name": "Root account",
                "version": "cloud",
                "product_family_code": "canvas",
                "validation_context": null
            },
            "clientId": "10000000000004",
            "platformId": "8421b0dc94540ac04bdf13cc5f7f4460",
            "deploymentId": "24:e7484a3d7fa6e228f44fc0fd50c318add6f918bf",
            "createdAt": "2020-11-13T03:43:04.941Z",
            "platformContext": {
                "roles": [
                    "http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator",
                    "http://purl.imsglobal.org/vocab/lis/v2/system/person#SysAdmin",
                    "http://purl.imsglobal.org/vocab/lis/v2/system/person#User"
                ],
                "contextId": "https%3A%2F%2Fcanvas.instructure.com1000000000000424%3Ae7484a3d7fa6e228f44fc0fd50c318add6f918bfe7484a3d7fa6e228f44fc0fd50c318add6f918bf_e7484a3d7fa6e228f44fc0fd50c318add6f918bf",
                "path": "/",
                "user": "a684e22b-9978-4cef-98d8-98ee5f4cfd6c",
                "targetLinkUri": "https://localhost:3003",
                "context": {
                    "id": "e7484a3d7fa6e228f44fc0fd50c318add6f918bf",
                    "label": "ACCT300",
                    "title": "Cost Accounting",
                    "type": [
                        "http://purl.imsglobal.org/vocab/lis/v2/course#CourseOffering"
                    ],
                    "validation_context": null
                },
                "resource": {
                    "id": "e7484a3d7fa6e228f44fc0fd50c318add6f918bf",
                    "description": null,
                    "title": null,
                    "validation_context": null
                },
                "launchPresentation": {
                    "document_target": "iframe",
                    "height": 500,
                    "width": 500,
                    "return_url": "http://dvseok.shop/courses/23/external_content/success/external_tool_redirect",
                    "locale": "en",
                    "validation_context": null
                },
                "messageType": "LtiResourceLinkRequest",
                "version": "1.3.0",
                "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"
                    ],
                    "lineitems": "http://dvseok.shop/api/lti/courses/23/line_items",
                    "validation_context": null
                },
                "namesRoles": {
                    "context_memberships_url": "http://dvseok.shop/api/lti/courses/23/names_and_roles",
                    "service_versions": [
                        "2.0"
                    ],
                    "validation_context": null
                },
                "createdAt": "2020-11-13T03:43:04.957Z"
            }
        },
        "context": {
            "roles": [
                "http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator",
                "http://purl.imsglobal.org/vocab/lis/v2/system/person#SysAdmin",
                "http://purl.imsglobal.org/vocab/lis/v2/system/person#User"
            ],
            "contextId": "https%3A%2F%2Fcanvas.instructure.com1000000000000424%3Ae7484a3d7fa6e228f44fc0fd50c318add6f918bfe7484a3d7fa6e228f44fc0fd50c318add6f918bf_e7484a3d7fa6e228f44fc0fd50c318add6f918bf",
            "path": "/",
            "user": "a684e22b-9978-4cef-98d8-98ee5f4cfd6c",
            "targetLinkUri": "https://localhost:3003",
            "context": {
                "id": "e7484a3d7fa6e228f44fc0fd50c318add6f918bf",
                "label": "ACCT300",
                "title": "Cost Accounting",
                "type": [
                    "http://purl.imsglobal.org/vocab/lis/v2/course#CourseOffering"
                ],
                "validation_context": null
            },
            "resource": {
                "id": "e7484a3d7fa6e228f44fc0fd50c318add6f918bf",
                "description": null,
                "title": null,
                "validation_context": null
            },
            "launchPresentation": {
                "document_target": "iframe",
                "height": 500,
                "width": 500,
                "return_url": "http://dvseok.shop/courses/23/external_content/success/external_tool_redirect",
                "locale": "en",
                "validation_context": null
            },
            "messageType": "LtiResourceLinkRequest",
            "version": "1.3.0",
            "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"
                ],
                "lineitems": "http://dvseok.shop/api/lti/courses/23/line_items",
                "validation_context": null
            },
            "namesRoles": {
                "context_memberships_url": "http://dvseok.shop/api/lti/courses/23/names_and_roles",
                "service_versions": [
                    "2.0"
                ],
                "validation_context": null
            },
            "createdAt": "2020-11-13T03:43:04.957Z"
        },
Cvmcosta commented 3 years ago

Hello, can you show me your package.json so i can confirm the ltijs version (1.3 is way too old).

The error log you showed implies that the error is coming from Canvas, not Ltijs. Can you walk me through the flow of use up until the names and roles call?

Also, do you have access to the canvas logs?

nmtoan251998 commented 3 years ago
// package.json
{
  "name": "ltijs-demo",
  "version": "1.0.0",
  "description": "Ltijs demo server",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "env DEBUG=provider:* node index.js"
  },
  "keywords": [
    "lti",
    "ims",
    "ltijs",
    "1.3",
    "imslti"
  ],
  "author": "cvmcosta",
  "license": "MIT",
  "dependencies": {
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "ltijs": "^5.3.3",
    "ltijs-sequelize": "^2.2.0"
  }
}
nmtoan251998 commented 3 years ago

Hmm you may right, when i tried to access the log from my canvas, it responses an error, not data

Cvmcosta commented 3 years ago

How is your Canvas installed? Manually or docker? Some docker images don't work well with LTI (Bitnami).

nmtoan251998 commented 3 years ago

I installed Canvas manually. Basically I have not made any modification to the source code from its open source version from this repo

Cvmcosta commented 3 years ago

Did you do a production installation? More specifically, did you do the Dynamic Settings installation step?

nmtoan251998 commented 3 years ago

There may be a misconfiguration for my Canvas project, thank you for the helpful guidance!

GTMtremolo commented 3 years ago

hello @Cvmcosta , I call menthod getMembers but the member response don't have email and name of user. This is my response

{ id: 'https://lms-dev.zhost.com.vn/api/lti/courses/1/names_and_roles', context: { id: '58d62d469b01f7668d89eb122134a968afee5975', label: 'test', title: 'test' }, members: [ { status: 'Active', user_id: 'e8637b4d-a821-4040-9c92-5c6f452b6902', lti11_legacy_user_id: 'e6e7af12037e588f106302ae894fa2452584db98', roles: [Array] } ] }

Do you know how to config to return member email ?

Cvmcosta commented 3 years ago

Hello @GTMtremolo, that depends on the LMS you are using.

On Moodle you have to configure the privacy settings in the Tool registration.

On Canvas you have to set the Privacy level as Public in the Additional Settings and make sure that "Can retrieve user data associated with the context the tool is installed in." is enabled in the LTI Advantage Services settings. Have in mind that for Developer Key changes to take effect you also have to delete your App and create a new one.

GTMtremolo commented 3 years ago

@Cvmcosta Thank you, it work