packbackbooks / lti-1-3-php-library

A library used for building IMS-certified LTI 1.3 tool providers in PHP.
Apache License 2.0
39 stars 25 forks source link

Make api request #88

Closed jacksontong closed 10 months ago

jacksontong commented 1 year ago

We would like to make API request on our own that I don't see it's available in the package, for example: we would like to get all courses from the Account navigation.

Is it possible to get the access token from the launch endpoint with the package and make the api request there?

https://canvas.instructure.com/doc/api/courses.html

public function launch(Request $request)
{
    $lti13Service = $this->lti13Service;
    $launch = new LtiMessageLaunch(
        $lti13Service->db,
        $lti13Service->cache,
        $lti13Service->cookie,
        $lti13Service->serviceConnector,
    );
    $launch->validate($request->all());
    if ($launch->isResourceLaunch()) {
        echo '<p>Resource Launch!</p>';
        // dd($request->all());
    } else if ($launch->isDeepLinkLaunch()) {
        echo '<p>Deep Linking Launch!</p>';
    } else {
        echo '<p>Unknown launch type</p>';
    }

    if ($launch->hasNrps()) {
        dump($launch->getNrps()->getMembers());
    }
}
dbhynds commented 1 year ago

To my knowledge, this isn't something that's possible via LTI, however it's entirely possible I'm wrong about this. If you can point me to where in the LTI 1.3 spec it defines this behavior, I'd be happy to build it into the library.

It sounds like what you're talking about, however, is making direct API calls to Canvas. The whole goal of LTI is to abstract away any LMS-specific functionality so that you don't have to be concerned about their specific API interface. As long as they're LTI compliant, it should matter whether you're dealing with Canvas, Moodle, D2L, etc. So making an API call to Canvas to get data not defined in the LTI spec would be outside of the scope of this library.

I hope that answers your question. Let me now if you have follow-up questions. And like I said, if you can point me to where in the LTI spec it defines this functionality, I can get that added in.