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

How to add multiple External Tool To single server of ltijs? #100

Open davinder-ficode opened 3 years ago

davinder-ficode commented 3 years ago

Describe the bug How to add multiple Tools/Activities so that whenever on Moodle "Add LTI Advantage" button pressed all tools can be register once with single url of tool provider?

Ltijs version

NodeJS version

Platform used

Cvmcosta commented 3 years ago

Hello! I don't know if i understood your question. Do you wanna know how to server multiple tools/resources using only one LTI provider (one registration on moodle)? If so, you can simply treat your LTI server as a gateway, and then you receive launches with an identifier and redirect the user to the specified resource.

Eg: You can receive launches at https://your.lti.server.com?resource=123 and redirect the user to resource 123. To make this work you can have a resource selection view that would be accessed via Deep Linking to automatically create these links

davinder-ficode commented 3 years ago

@Cvmcosta Thanks for quick reply, yes i think you understand my question right. I want to to register multiple tools using one LTI provider and then onConnect(), i can open/serve respective tool. Is that possible with ltijs?. If yes, a little code snippet can help me better. Thanks again for your help.

Cvmcosta commented 3 years ago

Sure, as i mentioned you can control access with the onConnect method using query parameters.

lti.onConnect((token, req, res) => {
  const resourceID = req.query.resource // Retrieving resource ID
  /**
  Find resource URL based on ID
  **/
  return lti.redirec(res, resourceURL)
})

Launches would be made to your LTI tool like so: https://your.tool.com?resource=123

davinder-ficode commented 3 years ago

@Cvmcosta thanks mate..i'll test this..really appreciate your help. I got your idea that how to serve multiple resource on onConnect(). But i still don't get how to register(LTI advantage) multiple tools on moodle with single tool-provider url ? i.e can i use lti.setup's "options.dynReg" as array of objects instead of single object? is this possible with ltijs?

dynReg: [ { url: 'https://test.tool-provider.com', // Tool Provider URL. Required field. name: 'name', // Tool Provider name. Required field. logo: 'http://tool.example.com/assets/logo.svg', // Tool Provider logo URL. description: 'description', // Tool Provider description. redirectUris: ['https://test.tool-provider.com/''], // Additional redirection URLs. The main URL is added by default. customParameters: { test_key: 'test_value' }, // Custom parameters. autoActivate: true // Whether or not dynamically registered Platforms should be automatically activated. Defaults to false. }, { url: 'https://test.tool-provider.com', // Tool Provider URL. Required field. name: 'name', // Tool Provider name. Required field. logo: 'http://tool.example.com/assets/logo.svg', // Tool Provider logo URL. description: 'description', // Tool Provider description. redirectUris: ['https://test.tool-provider.com/''], // Additional redirection URLs. The main URL is added by default. customParameters: { test_key: 'test_value' }, // Custom parameters. autoActivate: true // Whether or not dynamically registered Platforms should be automatically activated. Defaults to false. }, { url: 'https://test.tool-provider.com', // Tool Provider URL. Required field. name: 'name', // Tool Provider name. Required field. logo: 'http://tool.example.com/assets/logo.svg', // Tool Provider logo URL. description: 'description', // Tool Provider description. redirectUris: ['https://test.tool-provider.com/''], // Additional redirection URLs. The main URL is added by default. customParameters: { test_key: 'test_value' }, // Custom parameters. autoActivate: true // Whether or not dynamically registered Platforms should be automatically activated. Defaults to false. } ]

Cvmcosta commented 3 years ago

Hello, that would not work. You can only register one Tool at a time. In the scenario you described you only have one LTI Tool providing multiple resources, not multiple LTI Tools. So you only have to register the parent Tool