Error on signature of ContentItemSelectionRequest

Error on signature of ContentItemSelectionRequest

by Chris F -
Number of replies: 5

Hi,

I'm trying to develop an LTI app and I have almost everything set up to publish with an external tool, but when I call to content item return url Moodle returns an error saying "Exception - OAuth signature failed: Invalid signature ours= LeDuZRIV2w/OZ+HRPkUBQ+1n0qE= yours=xwXtczMGJxBG4I3uwxFgFxgHXb4=". I'm using the following content item definition

        $contentItem = [
            '@context' => 'http://purl.imsglobal.org/ctx/lti/v1/ContentItem',
            '@graph' => [
                [
                    '@type' => 'LtiLinkItem',
                    'url' => $link,
                    'title' => $title,
                    'text' => $instructions ?? '',
                    'mediaType' => 'application/vnd.ims.lti.v1.ltilink',
                    'placementAdvice' => ['presentationDocumentTarget' => 'frame'],
                    'thumbnail' => [
                        '@id' => $thumbnail,
                        'width' => 500,
                        'height' => 707
                    ],
                ],
            ],
        ];

And I'm signing it using the content item return url sent by Moodle at the launch, a new timestamp and nonce and the consumer secret. The method of signing is working (as far as I know) because the signature validation works on the launch request, so it must be something with the parameters, but I don't know what's going on. The parameters I send are

            [
                'oauth_consumer_key' => $consumerKey,
                'oauth_nonce' => $newNonce,
                'oauth_signature_method' => 'HHMAC-SHA1',
                'oauth_timestamp' => (new DateTime('now', new DateTimeZone('UTC')))->getTimestamp(),
                'oauth_version' => '1.0',
                'content_items' => json_encode($contentItem),
                'lti_message_type' => 'ContentItemSelection',
                'lti_version' => 'LTI-1p0',
            ],

Maybe someone has already done this and can shed some light on what's going on.

Thanks a lot

Average of ratings: -
In reply to Chris F

Re: Error on signature of ContentItemSelectionRequest

by Chris F -
I found the solution. Moodle was sending me a URL with query parameters and I was using the full URL, including the query parameters, to generate the oAuth signature. To generate the signature the URL must be without any query parameters, at least in this case. I hope this helps someone.
In reply to Chris F

Re: Error on signature of ContentItemSelectionRequest

by Jake Dallimore -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Glad you got it sorted, Chris. Worth also pointing out (in case you're not aware) that the LTI 1.1 standard has been deprecated for some time now in favor of LTI 1.3 and LTI Advantage. I'd strongly recommend building any new tools using this standard. At some stage in the future, LTI 1.1 support may be dropped from consumers.

Cheers,
In reply to Jake Dallimore

Re: Error on signature of ContentItemSelectionRequest

by Chris F -
I'm new to Moodle, but I downloaded the last version from the official downloads page and the request to the LTI tool I'm building came with a LTI-1p0 value. Is that LTI 1.1, 1.3 or anything 1,x?
In reply to Chris F

Re: Error on signature of ContentItemSelectionRequest

by Jake Dallimore -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
When you're configuring the tool in the Moodle LMS (via Site admin > Plugins > Activity Modules > External tool > Manage tools), you'll see an "LTI Version" field on the edit form. That should be set to LTI 1.3 if you want to use 1.3, or 1.0/1.1 if you want to use legacy. We support launching into both of course - it's just that I wouldn't recommend building a tool using the legacy specs in 2023, that's all.

Cheers
In reply to Jake Dallimore

Re: Error on signature of ContentItemSelectionRequest

by Chris F -
I'll check it out and I'll try to migrate the tool to LTI 1.3. But, I must say, the main problem is that the LTI documentation is already very difficult to find and to understand. Only lists of parameters, specification pages without much explanation and of course few or no examples. But I'll give it a try